Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start sound after sound in soundmanager2

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..

like image 492
averbaher Avatar asked Sep 24 '11 10:09

averbaher


2 Answers

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)

like image 162
Ashot Avatar answered Sep 19 '22 14:09

Ashot


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.

like image 39
James Allardice Avatar answered Sep 21 '22 14:09

James Allardice