异步加载url

This commit is contained in:
Harvey Zack committed 2018-10-25 18:04:42 +08:00
1 parent 552783e3ce
commit 4da0ac7650
4 files changed
+22 -8

No files matched your search

+6 -4
View File
@@ -1,4 +1,4 @@
import { clamp, secondToTime, setStorage } from './utils';
import { clamp, secondToTime, setStorage, sleep } from './utils';
import config from './config';
export default class Player {
@@ -20,7 +20,9 @@ export default class Player {
$video.volume = clamp(option.volume, 0, 1);
$video.poster = option.poster;
$video.autoplay = option.autoplay;
$video.src = option.url;
sleep().then(() => {
$video.src = option.url;
});
}
eventBind() {
@@ -91,11 +93,11 @@ export default class Player {
this.art.on('video:error', () => {
if (this.reconnectTime < this.maxReconnectTime) {
setTimeout(() => {
sleep(100).then(() => {
this.reconnectTime++;
$video.src = option.url;
notice.show(`${i18n.get('Reconnect')}: ${this.reconnectTime}`);
}, 1000);
});
} else {
this.art.isError = true;
this.art.isPlaying = false;
+4
View File
@@ -105,3 +105,7 @@ export function tooltip(target, msg, pos = 'up') {
target.setAttribute('data-balloon', msg);
target.setAttribute('data-balloon-pos', pos);
}
export function sleep(ms = 0) {
return new Promise(resolve => setTimeout(resolve, ms));
}