mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-29 11:11:20 -08:00
删除多余事件
This commit is contained in:
1 parent
e0faa3fe68
commit
7ff61b4660
38 files changed
+266
-516
No files matched your search
@@ -1,49 +0,0 @@
|
||||
import { getExt, sleep, errorHandle, def } from '../utils';
|
||||
|
||||
export default function attachUrlMix(art, player) {
|
||||
const {
|
||||
option: { type, customType },
|
||||
template: { $video },
|
||||
} = art;
|
||||
|
||||
def(player, 'url', {
|
||||
get() {
|
||||
return $video.src;
|
||||
},
|
||||
});
|
||||
|
||||
def(player, 'attachUrl', {
|
||||
value: url =>
|
||||
sleep().then(() => {
|
||||
function attachUrl(videoUrl) {
|
||||
const typeName = type || getExt(videoUrl);
|
||||
const typeCallback = customType[typeName];
|
||||
if (typeName && typeCallback) {
|
||||
art.loading.show = true;
|
||||
art.emit('beforeCustomType', typeName);
|
||||
typeCallback.call(art, $video, videoUrl, art);
|
||||
art.emit('afterCustomType', typeName);
|
||||
} else {
|
||||
art.emit('beforeAttachUrl', videoUrl);
|
||||
$video.src = videoUrl;
|
||||
art.emit('afterAttachUrl', videoUrl);
|
||||
}
|
||||
return Promise.resolve(videoUrl);
|
||||
}
|
||||
|
||||
if (typeof url === 'function') {
|
||||
const result = url.call(art);
|
||||
errorHandle(
|
||||
typeof result.then === 'function',
|
||||
'If url is a function, it needs to return a promise.',
|
||||
);
|
||||
return result.then(videoUrl => {
|
||||
art.loading.show = true;
|
||||
return attachUrl(videoUrl);
|
||||
});
|
||||
}
|
||||
|
||||
return attachUrl(url);
|
||||
}),
|
||||
});
|
||||
}
|
||||
@@ -3,9 +3,10 @@ import { clamp } from '../utils';
|
||||
export default function attrInit(art, player) {
|
||||
const {
|
||||
option,
|
||||
storage,
|
||||
template: { $video },
|
||||
} = art;
|
||||
|
||||
|
||||
Object.keys(option.moreVideoAttr).forEach(key => {
|
||||
$video[key] = option.moreVideoAttr[key];
|
||||
});
|
||||
@@ -13,11 +14,16 @@ export default function attrInit(art, player) {
|
||||
if (option.muted) {
|
||||
$video.muted = option.muted;
|
||||
}
|
||||
|
||||
|
||||
if (option.volume) {
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
}
|
||||
|
||||
const volume = storage.get('volume');
|
||||
if (volume) {
|
||||
$video.volume = clamp(volume, 0, 1);
|
||||
}
|
||||
|
||||
if (option.poster) {
|
||||
$video.poster = option.poster;
|
||||
}
|
||||
@@ -27,6 +33,5 @@ export default function attrInit(art, player) {
|
||||
}
|
||||
|
||||
$video.controls = false;
|
||||
|
||||
player.attachUrl(option.url);
|
||||
player.url = option.url;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ export default function eventInit(art, player) {
|
||||
if (reconnectTime < maxReconnectTime) {
|
||||
sleep(1000).then(() => {
|
||||
reconnectTime += 1;
|
||||
player.attachUrl(option.url);
|
||||
player.url = option.url;
|
||||
notice.show = `${i18n.get('Reconnect')}: ${reconnectTime}`;
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -2,59 +2,28 @@ import screenfull from 'screenfull';
|
||||
import { addClass, removeClass, def } from '../utils';
|
||||
|
||||
export default function fullscreenMix(art, player) {
|
||||
const {
|
||||
i18n,
|
||||
notice,
|
||||
events: { destroyEvents },
|
||||
template: { $player },
|
||||
} = art;
|
||||
|
||||
const screenfullChange = () => {
|
||||
art.emit('fullscreenChange', screenfull.isFullscreen);
|
||||
};
|
||||
|
||||
const screenfullError = () => {
|
||||
notice.show = i18n.get('Does not support fullscreen');
|
||||
};
|
||||
|
||||
if (player.fullscreenIsEnabled) {
|
||||
screenfull.on('change', screenfullChange);
|
||||
screenfull.on('error', screenfullError);
|
||||
destroyEvents.push(() => {
|
||||
screenfull.off('change', screenfullChange);
|
||||
screenfull.off('error', screenfullError);
|
||||
});
|
||||
}
|
||||
const { $player } = art.template;
|
||||
|
||||
def(player, 'fullscreen', {
|
||||
get() {
|
||||
return screenfull.isFullscreen;
|
||||
},
|
||||
set(value) {
|
||||
if (!player.fullscreenIsEnabled) {
|
||||
screenfullError();
|
||||
return;
|
||||
if (player.fullscreenWeb) {
|
||||
player.fullscreenWeb = false;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
if (player.fullscreenWeb) {
|
||||
player.fullscreenWeb = false;
|
||||
}
|
||||
|
||||
screenfull.request($player).then(() => {
|
||||
addClass($player, 'art-fullscreen');
|
||||
player.aspectRatioReset = true;
|
||||
art.emit('fullscreenEnabled');
|
||||
art.emit('fullscreenChange', true);
|
||||
});
|
||||
} else {
|
||||
if (player.fullscreenWeb) {
|
||||
player.fullscreenWeb = false;
|
||||
}
|
||||
|
||||
screenfull.exit().then(() => {
|
||||
removeClass($player, 'art-fullscreen');
|
||||
player.aspectRatioReset = true;
|
||||
art.emit('fullscreenExit');
|
||||
art.emit('fullscreenChange', false);
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -67,10 +36,4 @@ export default function fullscreenMix(art, player) {
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
def(player, 'fullscreenIsEnabled', {
|
||||
get() {
|
||||
return screenfull.isEnabled;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,29 +1,25 @@
|
||||
import { addClass, removeClass, hasClass, def } from '../utils';
|
||||
|
||||
export default function fullscreenWebMix(art, player) {
|
||||
const {
|
||||
template: { $player },
|
||||
} = art;
|
||||
const { $player } = art.template;
|
||||
|
||||
def(player, 'fullscreenWeb', {
|
||||
get() {
|
||||
return hasClass($player, 'art-web-fullscreen');
|
||||
},
|
||||
set(value) {
|
||||
if (player.fullscreen) {
|
||||
player.fullscreen = false;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
if (player.fullscreen) {
|
||||
player.fullscreen = false;
|
||||
}
|
||||
addClass($player, 'art-web-fullscreen');
|
||||
player.aspectRatioReset = true;
|
||||
art.emit('fullscreenWebEnabled');
|
||||
art.emit('fullscreenWebChange', true);
|
||||
} else {
|
||||
if (player.fullscreen) {
|
||||
player.fullscreen = false;
|
||||
}
|
||||
removeClass($player, 'art-web-fullscreen');
|
||||
player.aspectRatioReset = true;
|
||||
art.emit('fullscreenWebExit');
|
||||
art.emit('fullscreenWebChange', false);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import attachUrlMix from './attachUrlMix';
|
||||
import urlMix from './urlMix';
|
||||
import attrInit from './attrInit';
|
||||
import eventInit from './eventInit';
|
||||
import playMix from './playMix';
|
||||
@@ -25,7 +25,7 @@ import { proxyPropertys } from '../utils';
|
||||
|
||||
export default class Player {
|
||||
constructor(art) {
|
||||
attachUrlMix(art, this);
|
||||
urlMix(art, this);
|
||||
eventInit(art, this);
|
||||
attrInit(art, this);
|
||||
playMix(art, this);
|
||||
|
||||
@@ -29,17 +29,11 @@ function nativePip(art, player) {
|
||||
});
|
||||
|
||||
proxy($video, 'enterpictureinpicture', () => {
|
||||
art.emit('pipEnabled');
|
||||
art.emit('pipChange', true);
|
||||
});
|
||||
|
||||
proxy($video, 'leavepictureinpicture', () => {
|
||||
art.emit('pipExit');
|
||||
});
|
||||
|
||||
art.on('destroy', () => {
|
||||
if (player.pip) {
|
||||
player.pip = false;
|
||||
}
|
||||
art.emit('pipChange', false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,10 +49,10 @@ function webkitPip(art, player) {
|
||||
set(value) {
|
||||
if (value) {
|
||||
$video.webkitSetPresentationMode('picture-in-picture');
|
||||
art.emit('pipEnabled');
|
||||
art.emit('pipChange', true);
|
||||
} else {
|
||||
$video.webkitSetPresentationMode('inline');
|
||||
art.emit('pipExit');
|
||||
art.emit('pipChange', false);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -108,7 +102,7 @@ function customPip(art, player) {
|
||||
|
||||
append($pipTitle, option.title || i18n.get('Mini player'));
|
||||
|
||||
const property = {
|
||||
def(player, 'pip', {
|
||||
get() {
|
||||
return hasClass($player, 'art-pip');
|
||||
},
|
||||
@@ -124,8 +118,8 @@ function customPip(art, player) {
|
||||
player.fullscreenWeb = false;
|
||||
player.aspectRatio = false;
|
||||
player.playbackRate = false;
|
||||
art.emit('pipEnabled');
|
||||
} else if (player.pip) {
|
||||
art.emit('pipChange', true);
|
||||
} else {
|
||||
$player.style.cssText = cacheStyle;
|
||||
removeClass($player, 'art-pip');
|
||||
setStyle($player, 'top', null);
|
||||
@@ -135,12 +129,10 @@ function customPip(art, player) {
|
||||
player.aspectRatio = false;
|
||||
player.playbackRate = false;
|
||||
player.autoSize = true;
|
||||
art.emit('pipExit');
|
||||
art.emit('pipChange', false);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
def(player, 'pip', property);
|
||||
});
|
||||
}
|
||||
|
||||
export default function pipMix(art, player) {
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
import { def } from '../utils';
|
||||
|
||||
export default function switchMix(art, player) {
|
||||
const { i18n, notice, option } = art;
|
||||
const { i18n, notice } = art;
|
||||
|
||||
function switchUrl(url, name, currentTime) {
|
||||
if (url === player.url) return Promise.resolve(url);
|
||||
if (url === player.url) return;
|
||||
URL.revokeObjectURL(player.url);
|
||||
return player.attachUrl(url).then(() => {
|
||||
option.url = url;
|
||||
player.playbackRate = false;
|
||||
player.aspectRatio = false;
|
||||
art.once('video:canplay', () => {
|
||||
player.currentTime = currentTime;
|
||||
});
|
||||
if (player.playing) {
|
||||
player.play = true;
|
||||
}
|
||||
if (name) {
|
||||
notice.show = `${i18n.get('Switch video')}: ${name}`;
|
||||
}
|
||||
art.emit('switch', url);
|
||||
player.url = url;
|
||||
player.playbackRate = false;
|
||||
player.aspectRatio = false;
|
||||
art.once('video:canplay', () => {
|
||||
player.currentTime = currentTime;
|
||||
});
|
||||
if (player.playing) {
|
||||
player.play = true;
|
||||
}
|
||||
if (name) {
|
||||
notice.show = `${i18n.get('Switch video')}: ${name}`;
|
||||
}
|
||||
art.emit('switch', url);
|
||||
}
|
||||
|
||||
def(player, 'switchQuality', {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { getExt, def } from '../utils';
|
||||
|
||||
export default function urlMix(art, player) {
|
||||
const {
|
||||
option: { type, customType },
|
||||
template: { $video },
|
||||
} = art;
|
||||
|
||||
def(player, 'url', {
|
||||
get() {
|
||||
return $video.src;
|
||||
},
|
||||
set(url) {
|
||||
const typeName = type || getExt(url);
|
||||
const typeCallback = customType[typeName];
|
||||
if (typeName && typeCallback) {
|
||||
art.loading.show = true;
|
||||
typeCallback.call(art, $video, url, art);
|
||||
art.emit('customType', typeName);
|
||||
} else {
|
||||
$video.src = url;
|
||||
art.option.url = url;
|
||||
art.emit('urlChange', url);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user