Question

I'm trying to fire a function when my sound in SoundManager2 is finished playing, using onfinished. My code is as follows:

function createSound(id, path) {
    mySound = soundManager.createSound({
            id: id,
            url: path,
            volume: 100,
            onfinish: playNextSound(id),
            (...)
            },
    });
    return mySound;
}

function playNextSound(id) {
    (...)
    alert("Done!");
}

However, what happens is that the function fires (and the alert is shown) whenever I click play, which is obviously not what is supposed to happen. I've tried putting the onfinish inside the play() function as well, to no avail.

Any ideas what could be wrong?

Was it helpful?

Solution

Because you're executing the playNextSound function and assigning its returned value to onfinish.

You should be doing it like this:

onfinish: playNextSound,
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top