better handling play promise
This commit is contained in:
parent
c590dd4080
commit
e2e8884a45
|
|
@ -207,8 +207,10 @@ class APlayer {
|
|||
|
||||
this.template.list.scrollTop = this.playIndex * 33;
|
||||
|
||||
this.audio.src = this.options.music[this.playIndex].url;
|
||||
this.seek(0);
|
||||
this.handlePlayPromise(() => {
|
||||
this.audio.src = this.options.music[this.playIndex].url;
|
||||
this.seek(0);
|
||||
});
|
||||
if (this.paused) {
|
||||
this.pause();
|
||||
}
|
||||
|
|
@ -250,10 +252,11 @@ class APlayer {
|
|||
}, 100);
|
||||
}
|
||||
|
||||
const playedPromise = Promise.resolve(this.audio.play());
|
||||
playedPromise.catch(() => {
|
||||
this.pause();
|
||||
}).then(() => {
|
||||
this.handlePlayPromise(() => {
|
||||
this.playedPromise = Promise.resolve(this.audio.play());
|
||||
this.playedPromise.catch(() => {
|
||||
this.pause();
|
||||
});
|
||||
});
|
||||
|
||||
this.timer.enable('progress');
|
||||
|
|
@ -282,7 +285,9 @@ class APlayer {
|
|||
}, 100);
|
||||
}
|
||||
|
||||
this.audio.pause();
|
||||
this.handlePlayPromise(() => {
|
||||
this.audio.pause();
|
||||
});
|
||||
this.timer.disable('progress');
|
||||
}
|
||||
|
||||
|
|
@ -444,6 +449,17 @@ class APlayer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
handlePlayPromise (callback) {
|
||||
if (this.playedPromise) {
|
||||
this.playedPromise = this.playedPromise.then(() => {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default APlayer;
|
||||
|
|
|
|||
Loading…
Reference in New Issue