How can i start sound after sound in soundmanager2, i mean when the first sound ends, second sound to start and when the second end the third start and etc and etc..
var soundArray = ['sound1', 'sound2', ...];
var chain = function (sound) {
soundManager.play(sound, {
multiShotEvents: true,
onfinish: function () {
var index = soundArray.indexOf(sound);
if (soundArray[index + 1] !== undefined) {
chain(soundArray[index + 1]);
}
}});
};
chain(soundArray[0])
tray use recursion, the only problem can occur, when in array you put same sound twice(chain be infinity)
There is an example of how to do this in the documentation (see Demo 4a). The play
method takes an object as an argument. That object contains a set of options. One of those options is an onfinish
callback function:
soundManager.play('firstSound',{
multiShotEvents: true,
onfinish:function() {
soundManager.play('secondSound');
}
});
The multiShotEvents
option has to be set to true
to cause the onfinish
event to fire upon completion of each sound. By default it will only fire once sounds have finished.
You could queue up as many sounds as you wanted to this way really.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With