mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
分离播放器功能
This commit is contained in:
1 parent
3919ee2f3d
commit
617fd9681e
24 files changed
+671
-505
No files matched your search
@@ -1,14 +1,15 @@
|
||||
.artplayer-video-player .artplayer-subtitle{position:absolute;z-index:20;bottom:40px;width:100%;padding:0 20px;text-align:center;color:#fff;text-shadow:.5px .5px .5px rgba(0,0,0,.5);font-size:20px;pointer-events:none}.artplayer-video-player .artplayer-subtitle p{margin:5px 0}
|
||||
.artplayer-video-player{position:relative;width:100%;height:100%;overflow:hidden;outline:0;font-family:Roboto,Arial,Helvetica,sans-serif;color:#eee;text-align:left;direction:ltr;font-size:14px;line-height:1.3;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0);touch-action:manipulation;-ms-high-contrast-adjust:none}.artplayer-video-player *{box-sizing:border-box}.artplayer-video-player .art-icon{display:inline-block}.artplayer-video-player .art-icon svg{fill:#fff}
|
||||
.artplayer-video-player .artplayer-video{position:absolute;z-index:10;left:0;top:0;right:0;bottom:0;width:100%;height:100%;background-color:#000;outline:0;cursor:pointer}
|
||||
.artplayer-video-player{position:relative;width:100%;height:100%;overflow:hidden;outline:0;font-family:Roboto,Arial,Helvetica,sans-serif;color:#eee;text-align:left;direction:ltr;font-size:14px;line-height:1.3;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:rgba(0,0,0,0);touch-action:manipulation;-ms-high-contrast-adjust:none}.artplayer-video-player *{box-sizing:border-box}.artplayer-video-player .art-icon{display:inline-block;line-height:1.5}.artplayer-video-player .art-icon svg{fill:#fff}
|
||||
.artplayer-video-player .artplayer-subtitle{position:absolute;z-index:20;bottom:40px;width:100%;padding:0 20px;text-align:center;color:#fff;text-shadow:.5px .5px .5px rgba(0,0,0,.5);font-size:20px;pointer-events:none}.artplayer-video-player .artplayer-subtitle p{margin:5px 0}
|
||||
.artplayer-video-player .artplayer-layers{position:absolute;z-index:40;left:0;top:0;right:0;bottom:0;width:100%;height:100%;pointer-events:none}.artplayer-video-player .artplayer-layers .art-layer{position:absolute;pointer-events:all}
|
||||
.artplayer-video-player .artplayer-danmu{position:absolute;z-index:30;left:0;top:0;right:0;bottom:0;width:100%;height:100%;pointer-events:none}
|
||||
.artplayer-video-player .artplayer-mask{display:none;position:absolute;z-index:50;left:0;top:0;right:0;bottom:0;width:100%;height:100%;pointer-events:none}.artplayer-video-player .artplayer-mask .art-icon-playBig{position:absolute;right:30px;bottom:65px;opacity:.6}
|
||||
.artplayer-video-player .artplayer-loading{display:none;position:absolute;z-index:70;left:0;top:0;right:0;bottom:0;width:100%;height:100%;align-items:center;justify-content:center;pointer-events:none}
|
||||
.artplayer-video-player .artplayer-bottom{position:absolute;z-index:60;left:0;right:0;bottom:0;height:100px;padding:60px 10px 0;opacity:0;visibility:hidden;transition:all .2s ease-in-out;pointer-events:none;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==) repeat-x bottom}.artplayer-video-player .artplayer-bottom .artplayer-progress{position:relative;pointer-events:all}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress{position:relative;height:5px;padding:1px 0;cursor:pointer}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner{position:relative;height:100%;background:hsla(0,0%,100%,.2)}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-loaded{position:absolute;z-index:10;left:0;top:0;right:0;bottom:0;height:100%;width:0;background:hsla(0,0%,100%,.4)}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-played{position:absolute;z-index:20;left:0;top:0;right:0;bottom:0;height:100%;width:0}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-highlight{position:absolute;z-index:30;left:0;top:0;right:0;bottom:0;height:0}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-highlight span{display:inline-block;position:absolute;left:0;top:0;width:7px;height:3px;background:#fff;border-radius:3px}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-indicator{display:none;position:absolute;z-index:40;top:-5px;left:-6.5px;width:13px;height:13px;border-radius:50%}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-indicator.show-indicator{display:block}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress .art-control-progress-inner .art-progress-tip{display:none;position:absolute;z-index:50;top:-25px;left:0;height:20px;padding:0 5px;line-height:20px;color:#fff;font-size:12px;text-align:center;background:rgba(0,0,0,.7);border-radius:3px;font-weight:700}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress:hover .art-progress-indicator,.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-progress:hover .art-progress-tip{display:block}.artplayer-video-player .artplayer-bottom .artplayer-progress .art-control-thumbnails{display:none;position:absolute;bottom:8px;left:0;pointer-events:none;background-color:rgba(0,0,0,.7)}.artplayer-video-player .artplayer-bottom .artplayer-controls{position:relative;pointer-events:all;display:flex;align-items:center;justify-content:space-between;height:36px}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control{opacity:.9;float:left;font-size:12px;height:36px;line-height:36px;cursor:pointer}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control .art-icon{display:flex;align-items:center;justify-content:center;float:left;height:36px;width:36px;padding:7px}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control:hover{opacity:1}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel{position:relative;float:left;width:0;height:100%;transition:margin .2s cubic-bezier(.4,0,1,1),width .2s cubic-bezier(.4,0,1,1);overflow:hidden}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel .art-volume-slider-handle{position:absolute;top:50%;left:0;width:12px;height:12px;border-radius:12px;margin-top:-6px;background:#fff}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel .art-volume-slider-handle:before{left:-54px;background:#fff}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel .art-volume-slider-handle:after{left:6px;background:hsla(0,0%,100%,.2)}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel .art-volume-slider-handle:after,.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel .art-volume-slider-handle:before{content:"";position:absolute;display:block;top:50%;height:3px;margin-top:-2px;width:60px}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-volume .art-volume-panel.art-volume-panel-hover{width:60px}.artplayer-video-player .artplayer-bottom .artplayer-controls .art-control-time{padding:0 10px}.artplayer-video-playeLine truncated
|
||||
.artplayer-video-player .artplayer-notice{display:none;font-size:14px;position:absolute;z-index:80;left:0;top:0;padding:10px;width:100%;pointer-events:none}.artplayer-video-player .artplayer-notice .artplayer-notice-inner{display:inline-block;padding:5px 10px;color:#fff;background:rgba(0,0,0,.6);border-radius:3px}
|
||||
.artplayer-video-player .artplayer-setting{display:none;position:absolute;z-index:90;left:0;top:0;height:100%;width:100%;align-items:center;justify-content:center;pointer-events:none}.artplayer-video-player .artplayer-setting .artplayer-setting-inner{position:relative;width:350px;height:250px;font-size:12px;background:rgba(0,0,0,.8);border-radius:3px;pointer-events:all;overflow:hidden}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body{overflow-x:hidden;overflow-y:auto;width:365px;height:100%}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting{border-bottom:1px solid hsla(0,0%,100%,.1);padding:12px 35px 12px 20px}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting .art-setting-header{color:#fff;margin-bottom:10px}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting .art-setting-body{color:hsla(0,0%,100%,.8)}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-close{position:absolute;top:0;right:0;width:20px;height:20px;line-height:20px;text-align:center;color:hsla(0,0%,100%,.8);background:rgba(0,0,0,.5);font-size:20px;cursor:pointer}
|
||||
.artplayer-video-player .artplayer-contextmenu{position:absolute;z-index:100;left:0;top:0;min-width:200px;padding:5px 0;background:rgba(0,0,0,.8);border-radius:3px}.artplayer-video-player .artplayer-contextmenu .art-menu{cursor:pointer;font-size:13px;display:block;color:#fff;padding:7px 10px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-shadow:0 0 2px rgba(0,0,0,.5);border-bottom:1px solid hsla(0,0%,100%,.1)}.artplayer-video-player .artplayer-contextmenu .art-menu a{color:#fff;text-decoration:none}.artplayer-video-player .artplayer-contextmenu .art-menu span{display:inline-block;padding:0 7px}.artplayer-video-player .artplayer-contextmenu .art-menu span.current,.artplayer-video-player .artplayer-contextmenu .art-menu span:hover{color:#00c9ff}.artplayer-video-player .artplayer-contextmenu .art-menu:hover{background-color:hsla(0,0%,100%,.1)}.artplayer-video-player .artplayer-contextmenu .art-menu:last-child{border-bottom:none}
|
||||
.artplayer-video-player .artplayer-info{display:none;position:absolute;left:10px;top:10px;z-index:100;width:350px;min-height:150px;padding:10px;color:#fff;font-size:12px;font-family:Noto Sans CJK SC DemiLight,Roboto,Segoe UI,Tahoma,Arial,Helvetica,sans-serif;-webkit-font-smoothing:antialiased;background:rgba(0,0,0,.7)}.artplayer-video-player .artplayer-info .art-info-item{display:flex;margin-bottom:5px}.artplayer-video-player .artplayer-info .art-info-item .art-info-title{width:100px;text-align:right}.artplayer-video-player .artplayer-info .art-info-item .art-info-content{flex:1;padding-left:5px}.artplayer-video-player .artplayer-info .artplayer-info-close{position:absolute;top:5px;right:5px;cursor:pointer}
|
||||
.artplayer-video-player .artplayer-setting{display:none;position:absolute;z-index:90;left:0;top:0;height:100%;width:100%;align-items:center;justify-content:center;pointer-events:none}.artplayer-video-player .artplayer-setting .artplayer-setting-inner{position:relative;width:350px;height:250px;font-size:12px;background:rgba(0,0,0,.8);border-radius:3px;pointer-events:all;overflow:hidden}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body{overflow-x:hidden;overflow-y:auto;width:365px;height:100%}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting{border-bottom:1px solid hsla(0,0%,100%,.1);padding:12px 35px 12px 20px}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting .art-setting-header{color:#fff;margin-bottom:10px}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-body .art-setting .art-setting-body{color:hsla(0,0%,100%,.8)}.artplayer-video-player .artplayer-setting .artplayer-setting-inner .artplayer-setting-close{position:absolute;top:0;right:0;width:20px;height:20px;line-height:20px;text-align:center;color:hsla(0,0%,100%,.8);background:rgba(0,0,0,.5);font-size:20px;cursor:pointer}
|
||||
.artplayer-video-player[data-aspect-ratio] video{box-sizing:content-box;-o-object-fit:fill;object-fit:fill}
|
||||
.artplayer-video-player.artplayer-web-fullscreen{position:fixed;z-index:9999;width:100%;height:100%;left:0;top:0;right:0;bottom:0}
|
||||
button[data-balloon]{overflow:visible}[data-balloon]{position:relative;cursor:pointer}[data-balloon]:after{font-family:sans-serif!important;font-weight:400!important;font-style:normal!important;text-shadow:none!important;font-size:12px!important;background:rgba(17,17,17,.9);border-radius:4px;color:#fff;content:attr(data-balloon);padding:.5em 1em;white-space:nowrap}[data-balloon]:after,[data-balloon]:before{filter:alpha(opactiy=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";-moz-opacity:0;-khtml-opacity:0;opacity:0;pointer-events:none;transition:all .18s ease-out .18s;position:absolute;z-index:10}[data-balloon]:before{background:no-repeat url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='12'%3E%3Cpath fill='rgba(17,17,17,0.9)' d='M2.658 0h32.004c-6 0-11.627 12.002-16.002 12.002C14.285 12.002 8.594 0 2.658 0z'/%3E%3C/svg%3E");background-size:100% auto;width:18px;height:6px;content:""}[data-balloon]:hover:after,[data-balloon]:hover:before,[data-balloon][data-balloon-visible]:after,[data-balloon][data-balloon-visible]:before{filter:alpha(opactiy=100);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";-moz-opacity:1;-khtml-opacity:1;opacity:1;pointer-events:auto}[data-balloon].font-awesome:after{font-family:FontAwesome}[data-balloon][data-balloon-break]:after{white-space:pre}[data-balloon][data-balloon-blunt]:after,[data-balloon][data-balloon-blunt]:before{transition:none}[data-balloon][data-balloon-pos=up]:after{margin-bottom:11px}[data-balloon][data-balloon-pos=up]:after,[data-balloon][data-balloon-pos=up]:before{bottom:100%;left:50%;-webkit-transform:translate(-50%,10px);transform:translate(-50%,10px);-webkit-transform-origin:top;transform-origin:top}[data-balloon][data-balloon-pos=up]:before{margin-bottom:5px}[data-balloon][data-balloon-pos=up]:hover:after,[data-balloon][data-balloon-pos=up]:hover:before,[data-balloon][data-balloon-pos=up][data-balloon-visible]:after,[data-balloon][data-balloon-pos=up][data-balloon-visible]:before{-webkit-transform:translate(-50%);transform:translate(-50%)}[data-balloon][data-balloon-pos=up-left]:after{left:0;margin-bottom:11px}[data-balloon][data-balloon-pos=up-left]:after,[data-balloon][data-balloon-pos=up-left]:before{bottom:100%;-webkit-transform:translateY(10px);transform:translateY(10px);-webkit-transform-origin:top;transform-origin:top}[data-balloon][data-balloon-pos=up-left]:before{left:5px;margin-bottom:5px}[data-balloon][data-balloon-pos=up-left]:hover:after,[data-balloon][data-balloon-pos=up-left]:hover:before,[data-balloon][data-balloon-pos=up-left][data-balloon-visible]:after,[data-balloon][data-balloon-pos=up-left][data-balloon-visible]:before{-webkit-transform:translate(0);transform:translate(0)}[data-balloon][data-balloon-pos=up-right]:after{right:0;margin-bottom:11px}[data-balloon][data-balloon-pos=up-right]:after,[data-balloon][data-balloon-pos=up-right]:before{bottom:100%;-webkit-transform:translateY(10px);transform:translateY(10px);-webkit-transform-origin:top;transform-origin:top}[data-balloon][data-balloon-pos=up-right]:before{right:5px;margin-bottom:5px}[data-balloon][data-balloon-pos=up-right]:hover:after,[data-balloon][data-balloon-pos=up-right]:hover:before,[data-balloon][data-balloon-pos=up-right][data-balloon-visible]:after,[data-balloon][data-balloon-pos=up-right][data-balloon-visible]:before{-webkit-transform:translate(0);transform:translate(0)}[data-balloon][data-balloon-pos=down]:after{margin-top:11px}[data-balloon][data-balloon-pos=down]:after,[data-balloon][data-balloon-pos=down]:before{left:50%;top:100%;-webkit-transform:translate(-50%,-10px);transform:translate(-50%,-10px)}[data-balloon][data-balloon-pos=down]:before{background:no-repeat url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='12'%3E%3Cpath fill='rgba(17,17,17,0.9)' d='M33.342 12H1.338c6 0 11.627-12.002 16.002-12.002C21.715-.002 27.406 12 33.342 12z'/%3E%3C/svg%3E");background-size:100% auto;width:18px;height:6px;margin-top:5px}[data-balloon][data-balloon-pos=down]:hover:after,[data-balloon][data-balloon-pos=down]:hover:before,[data-balloon][data-balloon-pos=down][data-balloon-visible]:after,[data-balloon][data-balloon-pos=down][data-balloon-visible]:before{-webkit-transform:translate(-50%);transform:translate(-50%)}[data-balloon][data-balloon-pos=down-left]:after{left:0;margin-top:11px;top:100%;-webkit-transform:translateY(-10px);transform:translateY(-10px)}[data-balloon][data-balloon-pos=down-left]:before{background:no-repeat url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='36' height='12'%3E%3Cpath fill='rgba(17,17,17,0.9)' d='M33.342 12H1.338c6 0 11.627-12.002 16.002-12.002C21.715-.002 27.406 12 33.342 12z'/%3E%3C/svg%3E");background-size:100% auto;width:18px;height:6px;left:5px;margin-top:5px;top:100%;-webkit-transform:translateY(-10px);transform:translateY(-10px)}[data-balloon][data-balloon-pos=down-left]Line truncated
|
||||
+285
-242
@@ -677,6 +677,8 @@
|
||||
'Normal': '正常',
|
||||
'Switch video': '切换',
|
||||
'Switch subtitle': '切换字幕',
|
||||
'Web fullscreen': '网页全屏',
|
||||
'Exit web fullscreen': '退出网页全屏',
|
||||
'Common': '常规',
|
||||
'Hide setting': '隐藏设置',
|
||||
'Show setting': '显示设置'
|
||||
@@ -703,6 +705,8 @@
|
||||
'Normal': '正常',
|
||||
'Switch video': '切換',
|
||||
'Switch subtitle': '切換字幕',
|
||||
'Web fullscreen': '網頁全屏',
|
||||
'Exit web fullscreen': '退出網頁全屏',
|
||||
'Common': '常規',
|
||||
'Hide setting': '隱藏設置',
|
||||
'Show setting': '顯示設置'
|
||||
@@ -742,159 +746,117 @@
|
||||
return I18n;
|
||||
}();
|
||||
|
||||
var Player =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Player(art) {
|
||||
classCallCheck(this, Player);
|
||||
function attrInit(art) {
|
||||
var option = art.option,
|
||||
$video = art.refs.$video;
|
||||
Object.keys(option.moreVideoAttr).forEach(function (key) {
|
||||
$video[key] = option.moreVideoAttr[key];
|
||||
});
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
$video.poster = option.poster;
|
||||
$video.autoplay = option.autoplay;
|
||||
$video.src = option.url;
|
||||
}
|
||||
|
||||
this.art = art;
|
||||
this.init();
|
||||
this.eventBind();
|
||||
this.firstCanplay = false;
|
||||
this.reconnectTime = 0;
|
||||
this.maxReconnectTime = 5;
|
||||
}
|
||||
|
||||
createClass(Player, [{
|
||||
key: "init",
|
||||
value: function init() {
|
||||
var _this = this;
|
||||
|
||||
var _this$art = this.art,
|
||||
option = _this$art.option,
|
||||
_this$art$refs = _this$art.refs,
|
||||
$player = _this$art$refs.$player,
|
||||
$video = _this$art$refs.$video,
|
||||
_this$art$events = _this$art.events,
|
||||
proxy = _this$art$events.proxy,
|
||||
hover = _this$art$events.hover;
|
||||
Object.keys(option.moreVideoAttr).forEach(function (key) {
|
||||
$video[key] = option.moreVideoAttr[key];
|
||||
});
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
$video.poster = option.poster;
|
||||
$video.autoplay = option.autoplay;
|
||||
hover($player, function () {
|
||||
$player.classList.add('artplayer-hover');
|
||||
|
||||
_this.art.emit('hoverenter');
|
||||
}, function () {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
|
||||
_this.art.emit('hoverleave');
|
||||
});
|
||||
proxy($video, 'click', function () {
|
||||
_this.toggle();
|
||||
}); // TODO
|
||||
|
||||
$video.src = option.url;
|
||||
function eventInit(art, player) {
|
||||
var option = art.option,
|
||||
_art$events = art.events,
|
||||
proxy = _art$events.proxy,
|
||||
hover = _art$events.hover,
|
||||
_art$refs = art.refs,
|
||||
$player = _art$refs.$player,
|
||||
$video = _art$refs.$video,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
var firstCanplay = false;
|
||||
hover($player, function () {
|
||||
$player.classList.add('artplayer-hover');
|
||||
art.emit('hoverenter');
|
||||
}, function () {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.emit('hoverleave');
|
||||
});
|
||||
proxy($video, 'click', function () {
|
||||
player.toggle();
|
||||
});
|
||||
config.video.events.forEach(function (eventName) {
|
||||
proxy($video, eventName, function (event) {
|
||||
art.emit("video:".concat(event.type), event);
|
||||
});
|
||||
});
|
||||
art.on('video:loadstart', function () {
|
||||
art.loading.show();
|
||||
});
|
||||
art.on('video:loadeddata', function () {
|
||||
art.loading.hide();
|
||||
});
|
||||
art.on('video:waiting', function () {
|
||||
art.loading.show();
|
||||
});
|
||||
art.on('video:seeking', function () {
|
||||
art.loading.show();
|
||||
});
|
||||
art.on('video:canplay', function () {
|
||||
if (!firstCanplay) {
|
||||
firstCanplay = true;
|
||||
art.emit('firstCanplay');
|
||||
}
|
||||
}, {
|
||||
key: "eventBind",
|
||||
value: function eventBind() {
|
||||
var _this2 = this;
|
||||
|
||||
var _this$art2 = this.art,
|
||||
option = _this$art2.option,
|
||||
proxy = _this$art2.events.proxy,
|
||||
_this$art2$refs = _this$art2.refs,
|
||||
$player = _this$art2$refs.$player,
|
||||
$video = _this$art2$refs.$video,
|
||||
i18n = _this$art2.i18n,
|
||||
notice = _this$art2.notice;
|
||||
config.video.events.forEach(function (eventName) {
|
||||
proxy($video, eventName, function (event) {
|
||||
_this2.art.emit("video:".concat(event.type), event);
|
||||
});
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
art.loading.hide();
|
||||
|
||||
if (option.autoplay) {
|
||||
player.play();
|
||||
}
|
||||
});
|
||||
art.on('video:playing', function () {
|
||||
art.isPlaying = true;
|
||||
art.controls.hide();
|
||||
art.mask.hide();
|
||||
});
|
||||
art.on('video:pause', function () {
|
||||
art.isPlaying = false;
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
});
|
||||
art.on('video:ended', function () {
|
||||
art.isPlaying = false;
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
|
||||
if (option.loop) {
|
||||
player.seek(0);
|
||||
player.play();
|
||||
}
|
||||
});
|
||||
art.on('video:error', function () {
|
||||
if (player.reconnectTime < player.maxReconnectTime) {
|
||||
sleep(1000).then(function () {
|
||||
player.reconnectTime++;
|
||||
$video.src = option.url;
|
||||
notice.show("".concat(i18n.get('Reconnect'), ": ").concat(player.reconnectTime));
|
||||
});
|
||||
this.art.on('video:loadstart', function () {
|
||||
_this2.art.loading.show();
|
||||
});
|
||||
this.art.on('video:loadeddata', function () {
|
||||
_this2.art.loading.hide();
|
||||
});
|
||||
this.art.on('video:waiting', function () {
|
||||
_this2.art.loading.show();
|
||||
});
|
||||
this.art.on('video:seeking', function () {
|
||||
_this2.art.loading.show();
|
||||
});
|
||||
this.art.on('video:canplay', function () {
|
||||
if (!_this2.firstCanplay) {
|
||||
_this2.firstCanplay = true;
|
||||
|
||||
_this2.art.emit('firstCanplay');
|
||||
}
|
||||
|
||||
_this2.art.controls.show();
|
||||
|
||||
_this2.art.mask.show();
|
||||
|
||||
_this2.art.loading.hide();
|
||||
|
||||
if (option.autoplay) {
|
||||
_this2.play();
|
||||
}
|
||||
});
|
||||
this.art.on('video:playing', function () {
|
||||
_this2.art.isPlaying = true;
|
||||
|
||||
_this2.art.controls.hide();
|
||||
|
||||
_this2.art.mask.hide();
|
||||
});
|
||||
this.art.on('video:pause', function () {
|
||||
_this2.art.isPlaying = false;
|
||||
|
||||
_this2.art.controls.show();
|
||||
|
||||
_this2.art.mask.show();
|
||||
});
|
||||
this.art.on('video:ended', function () {
|
||||
_this2.art.isPlaying = false;
|
||||
|
||||
_this2.art.controls.show();
|
||||
|
||||
_this2.art.mask.show();
|
||||
|
||||
if (option.loop) {
|
||||
_this2.seek(0);
|
||||
|
||||
_this2.play();
|
||||
}
|
||||
});
|
||||
this.art.on('video:error', function () {
|
||||
if (_this2.reconnectTime < _this2.maxReconnectTime) {
|
||||
sleep(1000).then(function () {
|
||||
_this2.reconnectTime++;
|
||||
$video.src = option.url;
|
||||
notice.show("".concat(i18n.get('Reconnect'), ": ").concat(_this2.reconnectTime));
|
||||
});
|
||||
} else {
|
||||
_this2.art.isError = true;
|
||||
_this2.art.isPlaying = false;
|
||||
|
||||
_this2.art.loading.hide();
|
||||
|
||||
_this2.art.controls.hide();
|
||||
|
||||
$player.classList.add('artplayer-error');
|
||||
sleep(1000).then(function () {
|
||||
notice.show(i18n.get('Video load failed'), false);
|
||||
|
||||
_this2.art.destroy();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
art.isError = true;
|
||||
art.isPlaying = false;
|
||||
art.loading.hide();
|
||||
art.controls.hide();
|
||||
$player.classList.add('artplayer-error');
|
||||
sleep(1000).then(function () {
|
||||
notice.show(i18n.get('Video load failed'), false);
|
||||
art.destroy();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "play",
|
||||
value: function play() {
|
||||
var _this$art3 = this.art,
|
||||
$video = _this$art3.refs.$video,
|
||||
i18n = _this$art3.i18n,
|
||||
notice = _this$art3.notice;
|
||||
});
|
||||
}
|
||||
|
||||
function playMix(art, player) {
|
||||
Object.defineProperty(player, 'play', {
|
||||
value: function value() {
|
||||
var $video = art.refs.$video,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
var promise = $video.play();
|
||||
|
||||
if (promise !== undefined) {
|
||||
@@ -905,34 +867,41 @@
|
||||
}
|
||||
|
||||
notice.show(i18n.get('Play'));
|
||||
this.art.emit('play', $video);
|
||||
art.emit('play', $video);
|
||||
}
|
||||
}, {
|
||||
key: "pause",
|
||||
value: function pause() {
|
||||
var _this$art4 = this.art,
|
||||
$video = _this$art4.refs.$video,
|
||||
i18n = _this$art4.i18n,
|
||||
notice = _this$art4.notice;
|
||||
});
|
||||
}
|
||||
|
||||
function pauseMin(art, player) {
|
||||
Object.defineProperty(player, 'pause', {
|
||||
value: function value() {
|
||||
var $video = art.refs.$video,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
$video.pause();
|
||||
notice.show(i18n.get('Pause'));
|
||||
this.art.emit('pause', $video);
|
||||
art.emit('pause', $video);
|
||||
}
|
||||
}, {
|
||||
key: "toggle",
|
||||
value: function toggle() {
|
||||
if (this.art.isPlaying) {
|
||||
this.pause();
|
||||
});
|
||||
}
|
||||
|
||||
function toggleMix(art, player) {
|
||||
Object.defineProperty(player, 'toggle', {
|
||||
value: function value() {
|
||||
if (art.isPlaying) {
|
||||
player.pause();
|
||||
} else {
|
||||
this.play();
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "seek",
|
||||
value: function seek(time) {
|
||||
var _this$art5 = this.art,
|
||||
$video = _this$art5.refs.$video,
|
||||
notice = _this$art5.notice;
|
||||
});
|
||||
}
|
||||
|
||||
function seekMix(art, player) {
|
||||
Object.defineProperty(player, 'seek', {
|
||||
value: function value(time) {
|
||||
var $video = art.refs.$video,
|
||||
notice = art.notice;
|
||||
var newTime = Math.max(time, 0);
|
||||
|
||||
if ($video.duration) {
|
||||
@@ -941,15 +910,17 @@
|
||||
|
||||
$video.currentTime = newTime;
|
||||
notice.show("".concat(secondToTime(newTime), " / ").concat(secondToTime($video.duration)));
|
||||
this.art.emit('seek', newTime);
|
||||
art.emit('seek', newTime);
|
||||
}
|
||||
}, {
|
||||
key: "volume",
|
||||
value: function volume(percentage) {
|
||||
var _this$art6 = this.art,
|
||||
$video = _this$art6.refs.$video,
|
||||
i18n = _this$art6.i18n,
|
||||
notice = _this$art6.notice;
|
||||
});
|
||||
}
|
||||
|
||||
function volumeMix(art, player) {
|
||||
Object.defineProperty(player, 'volume', {
|
||||
value: function value(percentage) {
|
||||
var $video = art.refs.$video,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
|
||||
if (percentage !== undefined) {
|
||||
$video.volume = clamp(percentage, 0, 1);
|
||||
@@ -959,69 +930,96 @@
|
||||
setStorage('volume', $video.volume);
|
||||
}
|
||||
|
||||
this.art.emit('volume', $video.volume);
|
||||
art.emit('volume', $video.volume);
|
||||
}
|
||||
|
||||
return $video.volume || 0;
|
||||
}
|
||||
}, {
|
||||
key: "currentTime",
|
||||
value: function currentTime() {
|
||||
return this.art.refs.$video.currentTime || 0;
|
||||
});
|
||||
}
|
||||
|
||||
function currentTimeMix(art, player) {
|
||||
Object.defineProperty(player, 'currentTime', {
|
||||
value: function value() {
|
||||
return art.refs.$video.currentTime || 0;
|
||||
}
|
||||
}, {
|
||||
key: "duration",
|
||||
value: function duration() {
|
||||
return this.art.refs.$video.duration || 0;
|
||||
});
|
||||
}
|
||||
|
||||
function durationMix(art, player) {
|
||||
Object.defineProperty(player, 'duration', {
|
||||
value: function value() {
|
||||
return art.refs.$video.duration || 0;
|
||||
}
|
||||
}, {
|
||||
key: "switch",
|
||||
value: function _switch(url) {
|
||||
});
|
||||
}
|
||||
|
||||
function switchMix(art, player) {
|
||||
Object.defineProperty(player, 'switch', {
|
||||
value: function value(url) {
|
||||
var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Unknown';
|
||||
var _this$art7 = this.art,
|
||||
$video = _this$art7.refs.$video,
|
||||
i18n = _this$art7.i18n,
|
||||
notice = _this$art7.notice,
|
||||
isPlaying = _this$art7.isPlaying,
|
||||
option = _this$art7.option;
|
||||
var currentTime = this.currentTime();
|
||||
var $video = art.refs.$video,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice,
|
||||
isPlaying = art.isPlaying,
|
||||
option = art.option;
|
||||
var currentTime = player.currentTime();
|
||||
$video.src = url;
|
||||
option.url = url;
|
||||
this.reconnectTime = 0;
|
||||
this.seek(currentTime);
|
||||
player.removePlaybackRate();
|
||||
player.removeAspectRatio();
|
||||
player.reconnectTime = 0;
|
||||
player.seek(currentTime);
|
||||
|
||||
if (isPlaying) {
|
||||
this.play();
|
||||
player.play();
|
||||
}
|
||||
|
||||
this.resetStyle();
|
||||
notice.show("".concat(i18n.get('Switch video'), ": ").concat(name));
|
||||
this.art.emit('switch', url);
|
||||
art.emit('switch', url);
|
||||
}
|
||||
}, {
|
||||
key: "playbackRate",
|
||||
value: function playbackRate(rate) {
|
||||
var _this$art8 = this.art,
|
||||
_this$art8$refs = _this$art8.refs,
|
||||
$video = _this$art8$refs.$video,
|
||||
$player = _this$art8$refs.$player,
|
||||
i18n = _this$art8.i18n,
|
||||
notice = _this$art8.notice;
|
||||
});
|
||||
}
|
||||
|
||||
function playbackRateMix(art, player) {
|
||||
Object.defineProperty(player, 'playbackRate', {
|
||||
value: function value(rate) {
|
||||
var _art$refs = art.refs,
|
||||
$video = _art$refs.$video,
|
||||
$player = _art$refs.$player,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
var newRate = clamp(rate, 0.1, 10);
|
||||
$video.playbackRate = newRate;
|
||||
$player.dataset.playbackRate = newRate;
|
||||
notice.show("".concat(i18n.get('Rate'), ": ").concat(newRate === 1 ? i18n.get('Normal') : "".concat(newRate, "x")));
|
||||
this.art.emit('playbackRate', newRate);
|
||||
art.emit('playbackRate', newRate);
|
||||
}
|
||||
}, {
|
||||
key: "aspectRatio",
|
||||
value: function aspectRatio(ratio) {
|
||||
var _this$art9 = this.art,
|
||||
_this$art9$refs = _this$art9.refs,
|
||||
$video = _this$art9$refs.$video,
|
||||
$player = _this$art9$refs.$player,
|
||||
i18n = _this$art9.i18n,
|
||||
notice = _this$art9.notice;
|
||||
});
|
||||
Object.defineProperty(player, 'removePlaybackRate', {
|
||||
value: function value() {
|
||||
var $playbackRate = art.contextmenu.$playbackRate;
|
||||
|
||||
if ($playbackRate) {
|
||||
var $normal = $playbackRate.querySelector('.normal');
|
||||
sublings($normal).forEach(function (item) {
|
||||
return item.classList.remove('current');
|
||||
});
|
||||
$normal.classList.add('current');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function aspectRatioMix(art, player) {
|
||||
Object.defineProperty(player, 'aspectRatio', {
|
||||
value: function value(ratio) {
|
||||
console.log(1);
|
||||
var _art$refs = art.refs,
|
||||
$video = _art$refs.$video,
|
||||
$player = _art$refs.$player,
|
||||
i18n = art.i18n,
|
||||
notice = art.notice;
|
||||
var ratioName = ratio.length === 2 ? "".concat(ratio[0], ":").concat(ratio[1]) : i18n.get('Default');
|
||||
|
||||
if (ratio.length === 2) {
|
||||
@@ -1054,39 +1052,58 @@
|
||||
}
|
||||
|
||||
notice.show("".concat(i18n.get('Aspect ratio'), ": ").concat(ratioName));
|
||||
this.art.emit('aspectRatio', ratio);
|
||||
art.emit('aspectRatio', ratio);
|
||||
}
|
||||
}, {
|
||||
key: "resetStyle",
|
||||
value: function resetStyle() {
|
||||
var _this$art10 = this.art,
|
||||
$video = _this$art10.refs.$video,
|
||||
contextmenu = _this$art10.contextmenu;
|
||||
|
||||
if (contextmenu.$playbackRate) {
|
||||
var $normal = contextmenu.$playbackRate.querySelector('.normal');
|
||||
sublings($normal).forEach(function (item) {
|
||||
return item.classList.remove('current');
|
||||
});
|
||||
$normal.classList.add('current');
|
||||
}
|
||||
|
||||
});
|
||||
Object.defineProperty(player, 'removeAspectRatio', {
|
||||
value: function value() {
|
||||
var $video = art.refs.$video,
|
||||
$aspectRatio = art.contextmenu.$aspectRatio;
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
|
||||
if (contextmenu.$aspectRatio) {
|
||||
var $default = contextmenu.$aspectRatio.querySelector('.default');
|
||||
if ($aspectRatio) {
|
||||
var $default = $aspectRatio.querySelector('.default');
|
||||
sublings($default).forEach(function (item) {
|
||||
return item.classList.remove('current');
|
||||
});
|
||||
$default.classList.add('current');
|
||||
}
|
||||
}
|
||||
}]);
|
||||
});
|
||||
Object.defineProperty(player, 'resetAspectRatio', {
|
||||
value: function value() {
|
||||
var $player = art.refs.$player;
|
||||
var aspectRatio = $player.dataset.aspectRatio;
|
||||
console.log($player.dataset);
|
||||
console.log(aspectRatio);
|
||||
|
||||
return Player;
|
||||
}();
|
||||
if (aspectRatio) {
|
||||
player.aspectRatio(aspectRatio.split(':'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var Player = function Player(art) {
|
||||
classCallCheck(this, Player);
|
||||
|
||||
this.reconnectTime = 0;
|
||||
this.maxReconnectTime = 5;
|
||||
attrInit(art, this);
|
||||
eventInit(art, this);
|
||||
playMix(art, this);
|
||||
pauseMin(art, this);
|
||||
toggleMix(art, this);
|
||||
seekMix(art, this);
|
||||
volumeMix(art, this);
|
||||
currentTimeMix(art, this);
|
||||
durationMix(art, this);
|
||||
switchMix(art, this);
|
||||
playbackRateMix(art, this);
|
||||
aspectRatioMix(art, this);
|
||||
};
|
||||
|
||||
function _arrayWithHoles(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
@@ -1154,6 +1171,8 @@
|
||||
|
||||
var setting = "<svg xmlns=\"http://www.w3.org/2000/svg\" style=\"width: 100%; height: 100%\" viewBox=\"0 0 22 22\">\n <circle cx=\"11\" cy=\"11\" r=\"2\"></circle>\n <path d=\"M19.164 8.861L17.6 8.6a6.978 6.978 0 0 0-1.186-2.099l.574-1.533a1 1 0 0 0-.436-1.217l-1.997-1.153a1.001 1.001 0 0 0-1.272.23l-1.008 1.225a7.04 7.04 0 0 0-2.55.001L8.716 2.829a1 1 0 0 0-1.272-.23L5.447 3.751a1 1 0 0 0-.436 1.217l.574 1.533A6.997 6.997 0 0 0 4.4 8.6l-1.564.261A.999.999 0 0 0 2 9.847v2.306c0 .489.353.906.836.986l1.613.269a7 7 0 0 0 1.228 2.075l-.558 1.487a1 1 0 0 0 .436 1.217l1.997 1.153c.423.244.961.147 1.272-.23l1.04-1.263a7.089 7.089 0 0 0 2.272 0l1.04 1.263a1 1 0 0 0 1.272.23l1.997-1.153a1 1 0 0 0 .436-1.217l-.557-1.487c.521-.61.94-1.31 1.228-2.075l1.613-.269a.999.999 0 0 0 .835-.986V9.847a.999.999 0 0 0-.836-.986zM11 15a4 4 0 1 1 0-8 4 4 0 0 1 0 8z\"></path>\n</svg>";
|
||||
|
||||
var fullscreenWeb = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 22 22\" style=\"width: 80%; height: 80%\">\r\n\t<path d=\"M4,18h14V4H4V18z M6,6h10v10H6V6z\"/>\r\n\t<polygon points=\"2,16 0,16 0,22 6,22 6,20 2,20\"/>\r\n\t<polygon points=\"2,2 6,2 6,0 0,0 0,6 2,6\"/>\r\n\t<polygon points=\"20,20 16,20 16,22 22,22 22,16 20,16\"/>\r\n\t<polygon points=\"16,0 16,2 20,2 20,6 22,6 22,0\"/>\r\n</svg>\r\n";
|
||||
|
||||
var icons = {
|
||||
loading: loading,
|
||||
playBig: playBig,
|
||||
@@ -1164,7 +1183,8 @@
|
||||
subtitle: subtitle,
|
||||
screenshot: screenshot,
|
||||
danmu: danmu,
|
||||
setting: setting
|
||||
setting: setting,
|
||||
fullscreenWeb: fullscreenWeb
|
||||
};
|
||||
|
||||
function creatDomFromSvg(map) {
|
||||
@@ -1244,12 +1264,35 @@
|
||||
classCallCheck(this, FullscreenWeb);
|
||||
|
||||
this.option = option;
|
||||
this.state = false;
|
||||
}
|
||||
|
||||
createClass(FullscreenWeb, [{
|
||||
key: "apply",
|
||||
value: function apply(art, $control) {
|
||||
this.art = art;
|
||||
var _this = this;
|
||||
|
||||
var proxy = art.events.proxy,
|
||||
i18n = art.i18n,
|
||||
player = art.player,
|
||||
$player = art.refs.$player;
|
||||
this.$fullscreenWeb = append($control, icons$1.fullscreenWeb);
|
||||
tooltip(this.$fullscreenWeb, i18n.get('Web fullscreen'));
|
||||
proxy($control, 'click', function () {
|
||||
if (_this.state) {
|
||||
_this.state = false;
|
||||
$player.classList.remove('artplayer-web-fullscreen');
|
||||
setStyle(_this.$fullscreenWeb, 'opacity', '1');
|
||||
tooltip(_this.$fullscreenWeb, i18n.get('Web fullscreen'));
|
||||
} else {
|
||||
_this.state = true;
|
||||
$player.classList.add('artplayer-web-fullscreen');
|
||||
setStyle(_this.$fullscreenWeb, 'opacity', '0.8');
|
||||
tooltip(_this.$fullscreenWeb, i18n.get('Exit web fullscreen'));
|
||||
}
|
||||
|
||||
player.resetAspectRatio();
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../node_modules/option-validator/dist/option-validator.js","../../src/scheme/validElement.js","../../src/scheme/index.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../src/icons/index.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/fullscreen-web.js","../../src/controls/pip.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/screenshot.js","../../src/controls/quality.js","../../src/controls/index.js","../../src/contextmenu/playbackRate.js","../../src/contextmenu/aspectRatio.js","../../src/contextmenu/info.js","../../src/contextmenu/version.js","../../src/contextmenu/close.js","../../src/contextmenu/index.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/setting/common.js","../../src/setting/index.js","../../src/index.js"],"sourcesContent":["function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction _construct(Parent, args, Class) {\n if (isNativeReflectConstruct()) {\n module.exports = _construct = Reflect.construct;\n } else {\n module.exports = _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n\n return _construct.apply(null, arguments);\n}\n\nmodule.exports = _construct;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\"./arrayWithoutHoles\");\n\nvar iterableToArray = require(\"./iterableToArray\");\n\nvar nonIterableSpread = require(\"./nonIterableSpread\");\n\nfunction _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();\n}\n\nmodule.exports = _toConsumableArray;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n Line truncated
|
||||
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../node_modules/option-validator/dist/option-validator.js","../../src/scheme/validElement.js","../../src/scheme/index.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player/attrInit.js","../../src/player/eventInit.js","../../src/player/playMix.js","../../src/player/pauseMin.js","../../src/player/toggleMix.js","../../src/player/seekMix.js","../../src/player/volumeMix.js","../../src/player/currentTimeMix.js","../../src/player/durationMix.js","../../src/player/switchMix.js","../../src/player/playbackRateMix.js","../../src/player/aspectRatioMix.js","../../src/player/index.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../src/icons/index.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/fullscreen-web.js","../../src/controls/pip.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/screenshot.js","../../src/controls/quality.js","../../src/controls/index.js","../../src/contextmenu/playbackRate.js","../../src/contextmenu/aspectRatio.js","../../src/contextmenu/info.js","../../src/contextmenu/version.js","../../src/contextmenu/close.js","../../src/contextmenu/index.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/setting/common.js","../../src/setting/index.js","../../src/index.js"],"sourcesContent":["function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction _construct(Parent, args, Class) {\n if (isNativeReflectConstruct()) {\n module.exports = _construct = Reflect.construct;\n } else {\n module.exports = _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n\n return _construct.apply(null, arguments);\n}\n\nmodule.exports = _construct;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\".Line truncated
|
||||
@@ -1,9 +1,29 @@
|
||||
import { append, tooltip, setStyle } from '../utils';
|
||||
import icons from '../icons';
|
||||
|
||||
export default class FullscreenWeb {
|
||||
constructor(option) {
|
||||
this.option = option;
|
||||
this.state = false;
|
||||
}
|
||||
|
||||
apply(art, $control) {
|
||||
this.art = art;
|
||||
const { events: { proxy }, i18n, player, refs: { $player } } = art;
|
||||
this.$fullscreenWeb = append($control, icons.fullscreenWeb);
|
||||
tooltip(this.$fullscreenWeb, i18n.get('Web fullscreen'));
|
||||
proxy($control, 'click', () => {
|
||||
if (this.state) {
|
||||
this.state = false;
|
||||
$player.classList.remove('artplayer-web-fullscreen');
|
||||
setStyle(this.$fullscreenWeb, 'opacity', '1');
|
||||
tooltip(this.$fullscreenWeb, i18n.get('Web fullscreen'));
|
||||
} else {
|
||||
this.state = true;
|
||||
$player.classList.add('artplayer-web-fullscreen');
|
||||
setStyle(this.$fullscreenWeb, 'opacity', '0.8');
|
||||
tooltip(this.$fullscreenWeb, i18n.get('Exit web fullscreen'));
|
||||
}
|
||||
player.resetAspectRatio();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ let i18nMap = {
|
||||
'Normal': '正常',
|
||||
'Switch video': '切换',
|
||||
'Switch subtitle': '切换字幕',
|
||||
'Web fullscreen': '网页全屏',
|
||||
'Exit web fullscreen': '退出网页全屏',
|
||||
'Common': '常规',
|
||||
'Hide setting': '隐藏设置',
|
||||
'Show setting': '显示设置'
|
||||
@@ -47,6 +49,8 @@ let i18nMap = {
|
||||
'Normal': '正常',
|
||||
'Switch video': '切換',
|
||||
'Switch subtitle': '切換字幕',
|
||||
'Web fullscreen': '網頁全屏',
|
||||
'Exit web fullscreen': '退出網頁全屏',
|
||||
'Common': '常規',
|
||||
'Hide setting': '隱藏設置',
|
||||
'Show setting': '顯示設置'
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" style="width: 80%; height: 80%">
|
||||
<path d="M4,18h14V4H4V18z M6,6h10v10H6V6z"/>
|
||||
<polygon points="2,16 0,16 0,22 6,22 6,20 2,20"/>
|
||||
<polygon points="2,2 6,2 6,0 0,0 0,6 2,6"/>
|
||||
<polygon points="20,20 16,20 16,22 22,22 22,16 20,16"/>
|
||||
<polygon points="16,0 16,2 20,2 20,6 22,6 22,0"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 350 B |
+3
-1
@@ -8,6 +8,7 @@ import subtitle from './subtitle.svg';
|
||||
import screenshot from './screenshot.svg';
|
||||
import danmu from './danmu.svg';
|
||||
import setting from './setting.svg';
|
||||
import fullscreenWeb from './fullscreen-web.svg';
|
||||
|
||||
const icons = {
|
||||
loading,
|
||||
@@ -19,7 +20,8 @@ const icons = {
|
||||
subtitle,
|
||||
screenshot,
|
||||
danmu,
|
||||
setting
|
||||
setting,
|
||||
fullscreenWeb
|
||||
};
|
||||
|
||||
function creatDomFromSvg(map) {
|
||||
|
||||
-257
@@ -1,257 +0,0 @@
|
||||
import { clamp, secondToTime, setStorage, sleep, setStyle, sublings } from './utils';
|
||||
import config from './config';
|
||||
|
||||
export default class Player {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
this.init();
|
||||
this.eventBind();
|
||||
this.firstCanplay = false;
|
||||
this.reconnectTime = 0;
|
||||
this.maxReconnectTime = 5;
|
||||
}
|
||||
|
||||
init() {
|
||||
const { option, refs: { $player, $video }, events: { proxy, hover } } = this.art;
|
||||
Object.keys(option.moreVideoAttr).forEach(key => {
|
||||
$video[key] = option.moreVideoAttr[key];
|
||||
});
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
$video.poster = option.poster;
|
||||
$video.autoplay = option.autoplay;
|
||||
|
||||
hover($player, () => {
|
||||
$player.classList.add('artplayer-hover');
|
||||
this.art.emit('hoverenter');
|
||||
}, () => {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
this.art.emit('hoverleave');
|
||||
});
|
||||
|
||||
proxy($video, 'click', () => {
|
||||
this.toggle();
|
||||
});
|
||||
|
||||
// TODO
|
||||
$video.src = option.url;
|
||||
}
|
||||
|
||||
eventBind() {
|
||||
const { option, events: { proxy }, refs: { $player, $video }, i18n, notice } = this.art;
|
||||
|
||||
config.video.events.forEach(eventName => {
|
||||
proxy($video, eventName, event => {
|
||||
this.art.emit(`video:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
|
||||
this.art.on('video:loadstart', () => {
|
||||
this.art.loading.show();
|
||||
});
|
||||
|
||||
this.art.on('video:loadeddata', () => {
|
||||
this.art.loading.hide();
|
||||
});
|
||||
|
||||
this.art.on('video:waiting', () => {
|
||||
this.art.loading.show();
|
||||
});
|
||||
|
||||
this.art.on('video:seeking', () => {
|
||||
this.art.loading.show();
|
||||
});
|
||||
|
||||
this.art.on('video:canplay', () => {
|
||||
if (!this.firstCanplay) {
|
||||
this.firstCanplay = true;
|
||||
this.art.emit('firstCanplay');
|
||||
}
|
||||
|
||||
this.art.controls.show();
|
||||
this.art.mask.show();
|
||||
this.art.loading.hide();
|
||||
if (option.autoplay) {
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.art.on('video:playing', () => {
|
||||
this.art.isPlaying = true;
|
||||
this.art.controls.hide();
|
||||
this.art.mask.hide();
|
||||
});
|
||||
|
||||
this.art.on('video:pause', () => {
|
||||
this.art.isPlaying = false;
|
||||
this.art.controls.show();
|
||||
this.art.mask.show();
|
||||
});
|
||||
|
||||
this.art.on('video:ended', () => {
|
||||
this.art.isPlaying = false;
|
||||
this.art.controls.show();
|
||||
this.art.mask.show();
|
||||
if (option.loop) {
|
||||
this.seek(0);
|
||||
this.play();
|
||||
}
|
||||
});
|
||||
|
||||
this.art.on('video:error', () => {
|
||||
if (this.reconnectTime < this.maxReconnectTime) {
|
||||
sleep(1000).then(() => {
|
||||
this.reconnectTime++;
|
||||
$video.src = option.url;
|
||||
notice.show(`${i18n.get('Reconnect')}: ${this.reconnectTime}`);
|
||||
});
|
||||
} else {
|
||||
this.art.isError = true;
|
||||
this.art.isPlaying = false;
|
||||
this.art.loading.hide();
|
||||
this.art.controls.hide();
|
||||
$player.classList.add('artplayer-error');
|
||||
sleep(1000).then(() => {
|
||||
notice.show(i18n.get('Video load failed'), false);
|
||||
this.art.destroy();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
play() {
|
||||
const { refs: { $video }, i18n, notice } = this.art;
|
||||
const promise = $video.play();
|
||||
if (promise !== undefined) {
|
||||
promise.then().catch(err => {
|
||||
notice.show(err, true, 3000);
|
||||
console.warn(err);
|
||||
});
|
||||
}
|
||||
notice.show(i18n.get('Play'));
|
||||
this.art.emit('play', $video);
|
||||
}
|
||||
|
||||
pause() {
|
||||
const { refs: { $video }, i18n, notice } = this.art;
|
||||
$video.pause();
|
||||
notice.show(i18n.get('Pause'));
|
||||
this.art.emit('pause', $video);
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.art.isPlaying) {
|
||||
this.pause();
|
||||
} else {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
|
||||
seek(time) {
|
||||
const { refs: { $video }, notice } = this.art;
|
||||
let newTime = Math.max(time, 0);
|
||||
if ($video.duration) {
|
||||
newTime = Math.min(newTime, $video.duration);
|
||||
}
|
||||
$video.currentTime = newTime;
|
||||
notice.show(`${secondToTime(newTime)} / ${secondToTime($video.duration)}`);
|
||||
this.art.emit('seek', newTime);
|
||||
}
|
||||
|
||||
volume(percentage) {
|
||||
const { refs: { $video }, i18n, notice } = this.art;
|
||||
if (percentage !== undefined) {
|
||||
$video.volume = clamp(percentage, 0, 1);
|
||||
notice.show(`${i18n.get('Volume')}: ${parseInt($video.volume * 100)}`);
|
||||
if ($video.volume !== 0) {
|
||||
setStorage('volume', $video.volume);
|
||||
}
|
||||
this.art.emit('volume', $video.volume);
|
||||
}
|
||||
return $video.volume || 0;
|
||||
}
|
||||
|
||||
currentTime() {
|
||||
return this.art.refs.$video.currentTime || 0;
|
||||
}
|
||||
|
||||
duration() {
|
||||
return this.art.refs.$video.duration || 0;
|
||||
}
|
||||
|
||||
switch(url, name = 'Unknown') {
|
||||
const { refs: { $video }, i18n, notice, isPlaying, option } = this.art;
|
||||
const currentTime = this.currentTime();
|
||||
$video.src = url;
|
||||
option.url = url;
|
||||
this.reconnectTime = 0;
|
||||
this.seek(currentTime);
|
||||
if (isPlaying) {
|
||||
this.play();
|
||||
}
|
||||
this.resetStyle();
|
||||
notice.show(`${i18n.get('Switch video')}: ${name}`);
|
||||
this.art.emit('switch', url);
|
||||
}
|
||||
|
||||
playbackRate(rate) {
|
||||
const { refs: { $video, $player }, i18n, notice } = this.art;
|
||||
const newRate = clamp(rate, 0.1, 10);
|
||||
$video.playbackRate = newRate;
|
||||
$player.dataset.playbackRate = newRate;
|
||||
notice.show(`${i18n.get('Rate')}: ${newRate === 1 ? i18n.get('Normal') : `${newRate}x`}`);
|
||||
this.art.emit('playbackRate', newRate);
|
||||
}
|
||||
|
||||
aspectRatio(ratio) {
|
||||
const { refs: { $video, $player }, i18n, notice } = this.art;
|
||||
const ratioName = ratio.length === 2 ? `${ratio[0]}:${ratio[1]}` : i18n.get('Default');
|
||||
|
||||
if (ratio.length === 2) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const videoRatio = videoWidth / videoHeight;
|
||||
const setupRatio = Number(ratio[0]) / Number(ratio[1]);
|
||||
|
||||
if (videoRatio > setupRatio) {
|
||||
const percentage = setupRatio * videoHeight / videoWidth;
|
||||
setStyle($video, 'width', `${percentage * 100}%`);
|
||||
setStyle($video, 'height', '100%');
|
||||
setStyle($video, 'padding', `0 ${(clientWidth - clientWidth * percentage) / 2}px`);
|
||||
} else {
|
||||
const percentage = videoWidth / setupRatio / videoHeight;
|
||||
setStyle($video, 'width', '100%');
|
||||
setStyle($video, 'height', `${percentage * 100}%`);
|
||||
setStyle($video, 'padding', `${(clientHeight - clientHeight * percentage) / 2}px 0`);
|
||||
}
|
||||
|
||||
$player.dataset.aspectRatio = ratioName;
|
||||
} else {
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
delete $player.dataset.aspectRatio;
|
||||
}
|
||||
|
||||
notice.show(`${i18n.get('Aspect ratio')}: ${ratioName}`);
|
||||
this.art.emit('aspectRatio', ratio);
|
||||
}
|
||||
|
||||
resetStyle() {
|
||||
const { refs: { $video }, contextmenu } = this.art;
|
||||
|
||||
if (contextmenu.$playbackRate) {
|
||||
const $normal = contextmenu.$playbackRate.querySelector('.normal');
|
||||
sublings($normal).forEach(item => item.classList.remove('current'));
|
||||
$normal.classList.add('current');
|
||||
}
|
||||
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
if (contextmenu.$aspectRatio) {
|
||||
const $default = contextmenu.$aspectRatio.querySelector('.default');
|
||||
sublings($default).forEach(item => item.classList.remove('current'));
|
||||
$default.classList.add('current');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { setStyle, sublings } from '../utils';
|
||||
|
||||
export default function aspectRatioMix(art, player) {
|
||||
Object.defineProperty(player, 'aspectRatio', {
|
||||
value: ratio => {
|
||||
console.log(1);
|
||||
const { refs: { $video, $player }, i18n, notice } = art;
|
||||
const ratioName = ratio.length === 2 ? `${ratio[0]}:${ratio[1]}` : i18n.get('Default');
|
||||
|
||||
if (ratio.length === 2) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
const { clientWidth, clientHeight } = $player;
|
||||
const videoRatio = videoWidth / videoHeight;
|
||||
const setupRatio = Number(ratio[0]) / Number(ratio[1]);
|
||||
|
||||
if (videoRatio > setupRatio) {
|
||||
const percentage = setupRatio * videoHeight / videoWidth;
|
||||
setStyle($video, 'width', `${percentage * 100}%`);
|
||||
setStyle($video, 'height', '100%');
|
||||
setStyle($video, 'padding', `0 ${(clientWidth - clientWidth * percentage) / 2}px`);
|
||||
} else {
|
||||
const percentage = videoWidth / setupRatio / videoHeight;
|
||||
setStyle($video, 'width', '100%');
|
||||
setStyle($video, 'height', `${percentage * 100}%`);
|
||||
setStyle($video, 'padding', `${(clientHeight - clientHeight * percentage) / 2}px 0`);
|
||||
}
|
||||
|
||||
$player.dataset.aspectRatio = ratioName;
|
||||
} else {
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
delete $player.dataset.aspectRatio;
|
||||
}
|
||||
|
||||
notice.show(`${i18n.get('Aspect ratio')}: ${ratioName}`);
|
||||
art.emit('aspectRatio', ratio);
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'removeAspectRatio', {
|
||||
value: () => {
|
||||
const { refs: { $video }, contextmenu: { $aspectRatio } } = art;
|
||||
setStyle($video, 'width', null);
|
||||
setStyle($video, 'height', null);
|
||||
setStyle($video, 'padding', null);
|
||||
if ($aspectRatio) {
|
||||
const $default = $aspectRatio.querySelector('.default');
|
||||
sublings($default).forEach(item => item.classList.remove('current'));
|
||||
$default.classList.add('current');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'resetAspectRatio', {
|
||||
value: () => {
|
||||
const { refs: { $player } } = art;
|
||||
const { aspectRatio } = $player.dataset;
|
||||
console.log($player.dataset);
|
||||
console.log(aspectRatio);
|
||||
if (aspectRatio) {
|
||||
player.aspectRatio(aspectRatio.split(':'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { clamp } from '../utils';
|
||||
|
||||
export default function attrInit(art) {
|
||||
const { option, refs: { $video } } = art;
|
||||
Object.keys(option.moreVideoAttr).forEach(key => {
|
||||
$video[key] = option.moreVideoAttr[key];
|
||||
});
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
$video.poster = option.poster;
|
||||
$video.autoplay = option.autoplay;
|
||||
$video.src = option.url;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export default function currentTimeMix(art, player) {
|
||||
Object.defineProperty(player, 'currentTime', {
|
||||
value: () => art.refs.$video.currentTime || 0
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export default function durationMix(art, player) {
|
||||
Object.defineProperty(player, 'duration', {
|
||||
value: () => art.refs.$video.duration || 0
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import config from '../config';
|
||||
import { sleep } from '../utils';
|
||||
|
||||
export default function eventInit(art, player) {
|
||||
const { option, events: { proxy, hover }, refs: { $player, $video }, i18n, notice } = art;
|
||||
let firstCanplay = false;
|
||||
|
||||
hover($player, () => {
|
||||
$player.classList.add('artplayer-hover');
|
||||
art.emit('hoverenter');
|
||||
}, () => {
|
||||
$player.classList.remove('artplayer-hover');
|
||||
art.emit('hoverleave');
|
||||
});
|
||||
|
||||
proxy($video, 'click', () => {
|
||||
player.toggle();
|
||||
});
|
||||
|
||||
config.video.events.forEach(eventName => {
|
||||
proxy($video, eventName, event => {
|
||||
art.emit(`video:${event.type}`, event);
|
||||
});
|
||||
});
|
||||
|
||||
art.on('video:loadstart', () => {
|
||||
art.loading.show();
|
||||
});
|
||||
|
||||
art.on('video:loadeddata', () => {
|
||||
art.loading.hide();
|
||||
});
|
||||
|
||||
art.on('video:waiting', () => {
|
||||
art.loading.show();
|
||||
});
|
||||
|
||||
art.on('video:seeking', () => {
|
||||
art.loading.show();
|
||||
});
|
||||
|
||||
art.on('video:canplay', () => {
|
||||
if (!firstCanplay) {
|
||||
firstCanplay = true;
|
||||
art.emit('firstCanplay');
|
||||
}
|
||||
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
art.loading.hide();
|
||||
if (option.autoplay) {
|
||||
player.play();
|
||||
}
|
||||
});
|
||||
|
||||
art.on('video:playing', () => {
|
||||
art.isPlaying = true;
|
||||
art.controls.hide();
|
||||
art.mask.hide();
|
||||
});
|
||||
|
||||
art.on('video:pause', () => {
|
||||
art.isPlaying = false;
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
});
|
||||
|
||||
art.on('video:ended', () => {
|
||||
art.isPlaying = false;
|
||||
art.controls.show();
|
||||
art.mask.show();
|
||||
if (option.loop) {
|
||||
player.seek(0);
|
||||
player.play();
|
||||
}
|
||||
});
|
||||
|
||||
art.on('video:error', () => {
|
||||
if (player.reconnectTime < player.maxReconnectTime) {
|
||||
sleep(1000).then(() => {
|
||||
player.reconnectTime++;
|
||||
$video.src = option.url;
|
||||
notice.show(`${i18n.get('Reconnect')}: ${player.reconnectTime}`);
|
||||
});
|
||||
} else {
|
||||
art.isError = true;
|
||||
art.isPlaying = false;
|
||||
art.loading.hide();
|
||||
art.controls.hide();
|
||||
$player.classList.add('artplayer-error');
|
||||
sleep(1000).then(() => {
|
||||
notice.show(i18n.get('Video load failed'), false);
|
||||
art.destroy();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import attrInit from './attrInit';
|
||||
import eventInit from './eventInit';
|
||||
import playMix from './playMix';
|
||||
import pauseMin from './pauseMin';
|
||||
import toggleMix from './toggleMix';
|
||||
import seekMix from './seekMix';
|
||||
import volumeMix from './volumeMix';
|
||||
import currentTimeMix from './currentTimeMix';
|
||||
import durationMix from './durationMix';
|
||||
import switchMix from './switchMix';
|
||||
import playbackRateMix from './playbackRateMix';
|
||||
import aspectRatioMix from './aspectRatioMix';
|
||||
|
||||
export default class Player {
|
||||
constructor(art) {
|
||||
this.reconnectTime = 0;
|
||||
this.maxReconnectTime = 5;
|
||||
|
||||
attrInit(art, this);
|
||||
eventInit(art, this);
|
||||
playMix(art, this);
|
||||
pauseMin(art, this);
|
||||
toggleMix(art, this);
|
||||
seekMix(art, this);
|
||||
volumeMix(art, this);
|
||||
currentTimeMix(art, this);
|
||||
durationMix(art, this);
|
||||
switchMix(art, this);
|
||||
playbackRateMix(art, this);
|
||||
aspectRatioMix(art, this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export default function pauseMin(art, player) {
|
||||
Object.defineProperty(player, 'pause', {
|
||||
value: () => {
|
||||
const { refs: { $video }, i18n, notice } = art;
|
||||
$video.pause();
|
||||
notice.show(i18n.get('Pause'));
|
||||
art.emit('pause', $video);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export default function playMix(art, player) {
|
||||
Object.defineProperty(player, 'play', {
|
||||
value: () => {
|
||||
const { refs: { $video }, i18n, notice } = art;
|
||||
const promise = $video.play();
|
||||
if (promise !== undefined) {
|
||||
promise.then().catch(err => {
|
||||
notice.show(err, true, 3000);
|
||||
console.warn(err);
|
||||
});
|
||||
}
|
||||
notice.show(i18n.get('Play'));
|
||||
art.emit('play', $video);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { clamp, sublings } from '../utils';
|
||||
|
||||
export default function playbackRateMix(art, player) {
|
||||
Object.defineProperty(player, 'playbackRate', {
|
||||
value: rate => {
|
||||
const { refs: { $video, $player }, i18n, notice } = art;
|
||||
const newRate = clamp(rate, 0.1, 10);
|
||||
$video.playbackRate = newRate;
|
||||
$player.dataset.playbackRate = newRate;
|
||||
notice.show(`${i18n.get('Rate')}: ${newRate === 1 ? i18n.get('Normal') : `${newRate}x`}`);
|
||||
art.emit('playbackRate', newRate);
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(player, 'removePlaybackRate', {
|
||||
value: () => {
|
||||
const { contextmenu: { $playbackRate } } = art;
|
||||
if ($playbackRate) {
|
||||
const $normal = $playbackRate.querySelector('.normal');
|
||||
sublings($normal).forEach(item => item.classList.remove('current'));
|
||||
$normal.classList.add('current');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { secondToTime } from '../utils';
|
||||
|
||||
export default function seekMix(art, player) {
|
||||
Object.defineProperty(player, 'seek', {
|
||||
value: time => {
|
||||
const { refs: { $video }, notice } = art;
|
||||
let newTime = Math.max(time, 0);
|
||||
if ($video.duration) {
|
||||
newTime = Math.min(newTime, $video.duration);
|
||||
}
|
||||
$video.currentTime = newTime;
|
||||
notice.show(`${secondToTime(newTime)} / ${secondToTime($video.duration)}`);
|
||||
art.emit('seek', newTime);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export default function switchMix(art, player) {
|
||||
Object.defineProperty(player, 'switch', {
|
||||
value: (url, name = 'Unknown') => {
|
||||
const { refs: { $video }, i18n, notice, isPlaying, option } = art;
|
||||
const currentTime = player.currentTime();
|
||||
$video.src = url;
|
||||
option.url = url;
|
||||
player.removePlaybackRate();
|
||||
player.removeAspectRatio();
|
||||
player.reconnectTime = 0;
|
||||
player.seek(currentTime);
|
||||
if (isPlaying) {
|
||||
player.play();
|
||||
}
|
||||
notice.show(`${i18n.get('Switch video')}: ${name}`);
|
||||
art.emit('switch', url);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export default function toggleMix(art, player) {
|
||||
Object.defineProperty(player, 'toggle', {
|
||||
value: () => {
|
||||
if (art.isPlaying) {
|
||||
player.pause();
|
||||
} else {
|
||||
player.play();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { clamp, setStorage } from '../utils';
|
||||
|
||||
export default function volumeMix(art, player) {
|
||||
Object.defineProperty(player, 'volume', {
|
||||
value: percentage => {
|
||||
const { refs: { $video }, i18n, notice } = art;
|
||||
if (percentage !== undefined) {
|
||||
$video.volume = clamp(percentage, 0, 1);
|
||||
notice.show(`${i18n.get('Volume')}: ${parseInt($video.volume * 100)}`);
|
||||
if ($video.volume !== 0) {
|
||||
setStorage('volume', $video.volume);
|
||||
}
|
||||
art.emit('volume', $video.volume);
|
||||
}
|
||||
return $video.volume || 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
.art-icon {
|
||||
display: inline-block;
|
||||
line-height: 1.5;
|
||||
svg {
|
||||
fill: #fff;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
.artplayer-video-player {
|
||||
&.artplayer-web-fullscreen {
|
||||
position: fixed;
|
||||
z-index: 9999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
}
|
||||
@@ -11,3 +11,4 @@ import './contextmenu.scss';
|
||||
import './setting.scss';
|
||||
import './info.scss';
|
||||
import './aspectRatio.scss';
|
||||
import './fullscreenWeb.scss';
|
||||
Reference in new issue
Block a user