Frage

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?

War es hilfreich?

Lösung

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

You should be doing it like this:

onfinish: playNextSound,
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top