Skip to content

Commit

Permalink
Fix the problem of noise when playing web audio for more than 5 minut…
Browse files Browse the repository at this point in the history
…es. (#15807)

* Fix the problem of noise when playing web audio for more than 5 minutes.
  • Loading branch information
bofeng-song authored Jul 31, 2023
1 parent 45926d2 commit d73096a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pal/audio/minigame/player-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class OneShotAudioWeb {
this._bufferSourceNode.onended = null; // stop will call ended callback
audioBufferManager.tryReleasingCache(this._url);
this._bufferSourceNode.stop();
this._bufferSourceNode.disconnect();
this._bufferSourceNode.buffer = null;
}
}
Expand Down Expand Up @@ -278,7 +279,9 @@ export class AudioPlayerWeb implements OperationQueueable {
if (this._sourceNode) {
this._sourceNode.onended = null; // stop will call ended callback
this._sourceNode.stop();
this._sourceNode.disconnect();
this._sourceNode.buffer = null;
this._sourceNode = undefined;
}
} catch (e) {
// sourceNode can't be stopped twice, especially on Safari.
Expand Down
3 changes: 3 additions & 0 deletions pal/audio/web/player-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class OneShotAudioWeb {
clearTimeout(this._currentTimer);
audioBufferManager.tryReleasingCache(this._url);
this._bufferSourceNode.stop();
this._bufferSourceNode.disconnect();
this._bufferSourceNode.buffer = null;
}
}
Expand Down Expand Up @@ -438,7 +439,9 @@ export class AudioPlayerWeb implements OperationQueueable {
try {
if (this._sourceNode) {
this._sourceNode.stop();
this._sourceNode.disconnect();
this._sourceNode.buffer = null;
this._sourceNode = undefined;
}
} catch (e) {
// sourceNode can't be stopped twice, especially on Safari.
Expand Down

0 comments on commit d73096a

Please sign in to comment.