mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 14:41:20 -08:00
use async/await
This commit is contained in:
1 parent
facf8876b5
commit
e34d09a99c
9 files changed
+86
-102
No files matched your search
@@ -60,22 +60,20 @@ export default function eventInit(art) {
|
||||
}
|
||||
});
|
||||
|
||||
art.on('video:error', () => {
|
||||
art.on('video:error', async () => {
|
||||
if (reconnectTime < constructor.RECONNECT_TIME_MAX) {
|
||||
sleep(constructor.RECONNECT_SLEEP_TIME).then(() => {
|
||||
reconnectTime += 1;
|
||||
art.url = option.url;
|
||||
notice.show = `${i18n.get('Reconnect')}: ${reconnectTime}`;
|
||||
art.emit('error', reconnectTime);
|
||||
});
|
||||
await sleep(constructor.RECONNECT_SLEEP_TIME);
|
||||
reconnectTime += 1;
|
||||
art.url = option.url;
|
||||
notice.show = `${i18n.get('Reconnect')}: ${reconnectTime}`;
|
||||
art.emit('error', reconnectTime);
|
||||
} else {
|
||||
art.loading.show = false;
|
||||
art.controls.show = false;
|
||||
addClass($player, 'art-error');
|
||||
sleep(constructor.RECONNECT_SLEEP_TIME).then(() => {
|
||||
notice.show = i18n.get('Video Load Failed');
|
||||
art.destroy(false);
|
||||
});
|
||||
await sleep(constructor.RECONNECT_SLEEP_TIME);
|
||||
notice.show = i18n.get('Video Load Failed');
|
||||
art.destroy(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -13,26 +13,24 @@ const nativeScreenfull = (art) => {
|
||||
get() {
|
||||
return screenfull.isFullscreen;
|
||||
},
|
||||
set(value) {
|
||||
async set(value) {
|
||||
if (value) {
|
||||
art.normalSize = 'fullscreen';
|
||||
art.aspectRatioReset = true;
|
||||
art.autoSize = false;
|
||||
screenfull.request($player).then(() => {
|
||||
addClass($player, 'art-fullscreen');
|
||||
art.emit('resize');
|
||||
art.emit('fullscreen', true);
|
||||
notice.show = '';
|
||||
});
|
||||
await screenfull.request($player);
|
||||
addClass($player, 'art-fullscreen');
|
||||
art.emit('resize');
|
||||
art.emit('fullscreen', true);
|
||||
notice.show = '';
|
||||
} else {
|
||||
art.aspectRatioReset = true;
|
||||
art.autoSize = art.option.autoSize;
|
||||
screenfull.exit().then(() => {
|
||||
removeClass($player, 'art-fullscreen');
|
||||
art.emit('resize');
|
||||
art.emit('fullscreen');
|
||||
notice.show = '';
|
||||
});
|
||||
await screenfull.exit();
|
||||
removeClass($player, 'art-fullscreen');
|
||||
art.emit('resize');
|
||||
art.emit('fullscreen');
|
||||
notice.show = '';
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -42,12 +42,11 @@ export default function screenshotMix(art) {
|
||||
});
|
||||
|
||||
def(art, 'screenshot', {
|
||||
value: () => {
|
||||
return art.getDataURL().then((dataUri) => {
|
||||
download(dataUri, `${option.title || 'artplayer'}_${secondToTime($video.currentTime)}.png`);
|
||||
art.emit('screenshot', dataUri);
|
||||
return dataUri;
|
||||
});
|
||||
value: async () => {
|
||||
const dataUri = await art.getDataURL();
|
||||
download(dataUri, `${option.title || 'artplayer'}_${secondToTime($video.currentTime)}.png`);
|
||||
art.emit('screenshot', dataUri);
|
||||
return dataUri;
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -10,14 +10,13 @@ export default function urlMix(art) {
|
||||
get() {
|
||||
return $video.currentSrc;
|
||||
},
|
||||
set(url) {
|
||||
async set(url) {
|
||||
const typeName = option.type || getExt(url);
|
||||
const typeCallback = option.customType[typeName];
|
||||
if (typeName && typeCallback) {
|
||||
sleep().then(() => {
|
||||
art.loading.show = true;
|
||||
typeCallback.call(art, $video, url, art);
|
||||
});
|
||||
await sleep();
|
||||
art.loading.show = true;
|
||||
typeCallback.call(art, $video, url, art);
|
||||
} else {
|
||||
if (art.url && art.url !== url) {
|
||||
art.once('video:canplay', () => {
|
||||
|
||||
Reference in new issue
Block a user