I’m working on an app that allows sounds to play when certain objects are selected. Phaser 3.16.2. While the audio plays fine, I’m not getting a notification that it has stopped.
public playSong(): void {
if (!this.soundPlaying) {
this.soundPlaying = true;
const song = this.sound.add("song_1");
// These both display an accurate number
console.log(song.duration);
console.log(song.totalDuration);
song.on("ended", (sound) => {
// None of the following triggers
console.log("ended");
this.soundPlaying = false;
setTimeout(() => {
this.sys.game.destroy(true);
});
});
console.log("Play Song");
song.play();
}
}
Some code based upon http://labs.phaser.io/edit.html?src=src\audio\Web%20Audio\Reuse%20AudioContext.js
There’s approximately 30 sounds I might be playing, so I’m trying not to create a property on the scene for each sound.
What am I missing?