mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 13:51: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
@@ -37,13 +37,12 @@ export default function thumbnails(options) {
|
||||
}
|
||||
}
|
||||
|
||||
proxy($progress, 'mousemove', (event) => {
|
||||
proxy($progress, 'mousemove', async (event) => {
|
||||
if (!loading) {
|
||||
loading = true;
|
||||
loadImg(option.thumbnails.url).then((img) => {
|
||||
image = img;
|
||||
isLoad = true;
|
||||
});
|
||||
const img = await loadImg(option.thumbnails.url);
|
||||
image = img;
|
||||
isLoad = true;
|
||||
}
|
||||
|
||||
if (isLoad) {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function autoOrientation(art) {
|
||||
}
|
||||
});
|
||||
|
||||
art.on('fullscreen', (state) => {
|
||||
art.on('fullscreen', async (state) => {
|
||||
const lastOrientation = screen.orientation.type;
|
||||
if (state) {
|
||||
const { videoWidth, videoHeight } = $video;
|
||||
@@ -50,15 +50,13 @@ export default function autoOrientation(art) {
|
||||
(videoWidth < videoHeight && viewWidth > viewHeight)
|
||||
) {
|
||||
const oppositeOrientation = lastOrientation.startsWith('portrait') ? 'landscape' : 'portrait';
|
||||
screen.orientation.lock(oppositeOrientation).then(() => {
|
||||
addClass($player, 'art-auto-orientation-fullscreen');
|
||||
});
|
||||
await screen.orientation.lock(oppositeOrientation);
|
||||
addClass($player, 'art-auto-orientation-fullscreen');
|
||||
}
|
||||
} else {
|
||||
if (hasClass($player, 'art-auto-orientation-fullscreen')) {
|
||||
screen.orientation.lock(lastOrientation).then(() => {
|
||||
removeClass($player, 'art-auto-orientation-fullscreen');
|
||||
});
|
||||
await screen.orientation.lock(lastOrientation);
|
||||
removeClass($player, 'art-auto-orientation-fullscreen');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -50,15 +50,14 @@ export default class Subtitle extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
switch(url, newOption = {}) {
|
||||
async switch(url, newOption = {}) {
|
||||
const { i18n, notice, option } = this.art;
|
||||
const subtitleOption = { ...option.subtitle, ...newOption, url };
|
||||
return this.init(subtitleOption).then((subUrl) => {
|
||||
if (newOption.name) {
|
||||
notice.show = `${i18n.get('Switch Subtitle')}: ${newOption.name}`;
|
||||
}
|
||||
return subUrl;
|
||||
});
|
||||
const subUrl = await this.init(subtitleOption);
|
||||
if (newOption.name) {
|
||||
notice.show = `${i18n.get('Switch Subtitle')}: ${newOption.name}`;
|
||||
}
|
||||
return subUrl;
|
||||
}
|
||||
|
||||
init(subtitleOption) {
|
||||
|
||||
Reference in new issue
Block a user