Jump to content

Is it possible to detect when an AudioSprite has finished playing


Revox
 Share

Recommended Posts

I'm loading and playing an AudioSprite with JSON which works fine. But when I try to listen for the end of the sound I get a type Error.

game.load.audiosprite('sfx', ["snd/animalSounds.mp3", "snd/animalSounds.ogg"], "snd/animalSounds.json",true);
fx = game.add.audioSprite('sfx');
fx.allowMultiple = true;
fx.play("intro");
fx.onStop.add(soundStopped ,this);

 
onloadphaser.js:70687TypeError: undefined is not an object (evaluating 'fx.onStop.add') 

 

Can this be done using .onStop? 

Link to comment
Share on other sites

fx is global, that was my first thought. but I was successfully logging out fx on the line before the onStop listener. That made me think that I needed to add the onStop to a sound rather than the audioSprite. Then found onMarkerComplete andI was able to get this to work.


game.load.audiosprite('sfx', ["snd/animalSounds.mp3", "snd/animalSounds.ogg"], "snd/animalSounds.json",true);
fx = game.add.audioSprite('sfx');
fx.allowMultiple = true;
fx.play("intro");

console.log(fx);

fx.sounds.intro.onMarkerComplete.add(function(key) {console.log("  Done Playing “+key); })

 

It works. I’m not sure if this is the intended implementation.

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...