fix playedPromise overwrited in play

This commit is contained in:
DIYgod 2018-03-08 17:19:23 +08:00
parent cf5972879a
commit fb4211a0b0
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 8 additions and 18 deletions

View File

@ -26,6 +26,7 @@ class APlayer {
this.container = this.options.container;
this.playIndex = 0;
this.paused = true;
this.playedPromise = Promise.resolve();
this.randomOrder = utils.randomOrder(this.options.music.length);
@ -208,13 +209,6 @@ class APlayer {
this.audio.src = this.options.music[this.playIndex].url;
this.seek(0);
if (this.paused) {
this.pause();
}
else {
this.play();
}
this.lrc && this.lrc.switch(this.playIndex);
// set duration time
@ -251,7 +245,8 @@ class APlayer {
}, 100);
}
this.playedPromise = Promise.resolve(this.audio.play()).catch(() => {
const playPromise = Promise.resolve(this.audio.play()).catch((err) => {
console.error(err);
this.pause();
});
@ -264,6 +259,8 @@ class APlayer {
}
}
}
return playPromise;
});
}
@ -448,16 +445,9 @@ class APlayer {
}
handlePlayPromise (callback) {
if (this.playedPromise) {
this.playedPromise = this.playedPromise.then(() => {
callback();
}).catch((err) => {
console.error(err);
});
}
else {
callback();
}
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
console.error(err);
});
}
}