[2.0 Beta] Sounds don't play the first time if stop is called prior to loading
Inside of the stop method, there's an event handler that registers for 'play' that forces the sound to stop. This is problematic as large sound assets take quite a bit of time to load and something in the game (such as a different event handler) could prompt that the audio stop playing prior to it loading completely.
Can you explain why this would ever be desirable behaviour?
var self = this;
// Wait for the sound to begin playing before stopping it.
if (!self._loaded) {
if (typeof self._sounds[0]._sprite !== 'undefined') {
self.once('play', function() {
self.stop(id);
});
}
return self;
}
To fix this for myself, I just commented out the nested if block and the game now plays audio as it's supposed to.
The following would not work as expected if this were removed as the sound would play when the expected behavior would be for it not to:
sound.play();
sound.stop();
Understandable. Would it be possible to have the stop method determine if a play event is queued and then kill that handler instead of registering for play only to stop?
That way, the following code will work: sound.play(); sound.stop(); sound.play();
This should now be fixed with f84c2d29bdbdf7355e8d611b0e96648eef8fcb17. I replaced all of those internal event listeners with a load queue. It'll add anything you call before the sound loads to a queue that will then get executed in order after load.