mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 01:26:16 -08:00
异步加载url
This commit is contained in:
1 parent
552783e3ce
commit
4da0ac7650
4 files changed
+22
-8
No files matched your search
+6
-4
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
Reference in new issue
Block a user