fix wx one shot audio doesn't restart (#5699)

This commit is contained in:
Yun Hsiao Wu
2019-11-07 18:59:54 +08:00
committed by pandamicro
parent 9420d57761
commit eeacefc88f
3 changed files with 10 additions and 7 deletions
+2
View File
@@ -69,6 +69,7 @@ export class AudioPlayerDOM extends AudioPlayer {
const promise = this._audio.play();
if (!promise) { // Chrome50/Firefox53 below
// delay eval here to yield uniform behavior with other platforms
this._state = PlayingState.PLAYING;
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, this._post_gesture);
return;
}
@@ -98,6 +99,7 @@ export class AudioPlayerDOM extends AudioPlayer {
const promise = this._audio.play();
if (!promise) {
// delay eval here to yield uniform behavior with other platforms
this._state = PlayingState.PLAYING;
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, this._post_play);
return;
}
+5 -3
View File
@@ -70,11 +70,13 @@ export class AudioPlayerWeb extends AudioPlayer {
this._sourceNode.buffer = this._audio;
this._sourceNode.loop = this._loop;
this._sourceNode.connect(this._gainNode);
this._sourceNode.start(0, this._offset);
this._state = PlayingState.PLAYING;
this._startTime = this._context.currentTime;
// delay eval here to yield uniform behavior with other platforms
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, () => { this._eventTarget.emit('started'); });
cc.director.once(cc.Director.EVENT_AFTER_UPDATE, () => {
this._sourceNode.start(0, this._offset);
this._eventTarget.emit('started');
this._state = PlayingState.PLAYING;
});
/* still not supported by all platforms *
this._sourceNode.onended = this._on_ended;
/* doing it manually for now */
+3 -4
View File
@@ -108,11 +108,10 @@ export class AudioPlayerWX extends AudioPlayer {
same time so here we fall back to re-start style approach */
if (!this._audio) { return; }
this._offset = 0;
this._audio.seek(0);
this._audio.volume = volume;
if (this._oneShoting) { return; }
this._audio.loop = false;
this._oneShoting = true;
this._audio.stop();
this._audio.loop = false;
this._audio.volume = volume;
this._audio.play();
}