CreateJS / SoundJS

A Javascript library for working with Audio. It provides a consistent API for loading and playing audio on different browsers and devices. Currently supports WebAudio, HTML5 Audio, Cordova / PhoneGap, and a Flash fallback.
http://createjs.com/
MIT License
4.44k stars 835 forks source link

Succeeded Event Not Firing #251

Closed peterbrowse closed 6 years ago

peterbrowse commented 8 years ago

In version 0.6.2, the succeeded event is not being triggered on playback. The _beginPlaying event is firing and reporting correctly, but the event dispatcher is never being called for the succeeded event upon audio playback successfully starting as documented.

I've put a temporary fix into a version i've got included in my project, where I'm calling a local function, and it's then behaving as intended, but a little stumped as to why that specific this._sendEvent("succeeded"); isn't behaving as expected.

lannymcnie commented 8 years ago

Will check it out. Any chance you have a sample handy?

peterbrowse commented 8 years ago

Sure...

I'm loading the sounds in a preloader, I believe as documented:

preloader_one = new createjs.LoadQueue(true, "", true);
preloader_two = new createjs.LoadQueue(true, "", true);

preloader_one.installPlugin(createjs.Sound);
preloader_two.installPlugin(createjs.Sound);

preloader_one.on("complete", preloader_one_complete);
preloader_two.on("complete", preloader_two_complete);

preloader_one.on("progress", preloader_one_progress);
preloader_two.on("progress", preloader_two_progress);

preloader_one.on("error", preloader_error);
preloader_two.on("error", preloader_error);

And then in a button press scope, which is aware of the load status of the preloaders, i'm calling the following commands to play the sound:

track = createjs.Sound.play(track_id_list[now_playing], {volume:0});
track.on("succeeded", sound_playing);
track.on("complete", sound_finished);

The track.on("complete", sound_finished); is called as expect at the end of the sound, but the track.on("succeeded", sound_playing); never get's called, as mentioned above.

I've got round this by putting a call to sound_playing in soundjs in the p._beginPlaying function on line 5990 (in combined).

Let me know if you need anything else to give it context.

Nice one.

lannymcnie commented 7 years ago

Interesting. Will definitely check it out.

lannymcnie commented 6 years ago

So it looks like this is actually impossible using play because the "succeeded" event is called synchronously. In order to get "succeeded", you have to create the instance first, or call play() on an existing instance:

var inst = createjs.Sound.createInstance(...);
inst.on("succeeded", fn);
inst.play(...);

Alternately, you can check the playState of the instance, and check for "succeeded".