Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ namespace gdjs {
*/
private _rate: float;

/**
* Set to true when stop() is called so that a pending deferred play
* (scheduled via `once('load', ...)`) does not start the sound.
*/
private _stopped: boolean = false;

/**
* An array of callbacks to call once the sound starts to play.
*/
Expand Down Expand Up @@ -179,7 +185,10 @@ namespace gdjs {
this._oncePlay.forEach((func) => func(newID));
this._onPlay = [];
this._oncePlay = [];
} else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded
} else
this._howl.once('load', () => {
if (!this._stopped) this.play();
}); // Play only once the howl is fully loaded
} catch (error) {
handleHowlerSoundMethodError(error, 'play');
}
Expand All @@ -205,6 +214,7 @@ namespace gdjs {
*/
stop(): this {
try {
this._stopped = true;
if (this._id !== null && this.isActualId()) this._howl.stop(this._id);
} catch (error) {
handleHowlerSoundMethodError(error, 'stop');
Expand All @@ -219,6 +229,7 @@ namespace gdjs {
* to preload the sounds.
*/
playing(): boolean {
if (this._stopped) return false;
const isSoundPlaying =
this._id !== null ? this._howl.playing(this._id) : true;
return (
Expand Down
Loading