mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
fix wx one shot audio doesn't restart (#5699)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user