Reputation: 7766
I am trying to as the title reads play buzz.js
sound objects one after another. I have tried using the events - ended
callback but this becomes rigorous with a large set of files. I thought i could create my list of sounds, iterate through them and call the bind one time but that didn't work as the iteration doesn't wait for the call back to finish. I am using node.js.
Here is what i have so far:
var mySound1 = new buzz.sound("/sound/001000.mp3");
var mySound2 = new buzz.sound('/sound/001001.mp3');
var mySound3 = new buzz.sound('/sound/001002.mp3');
for (var i = 0, max = 3; i < max; i++) {
var sPath = '/sound/001' + soundArray[i].value + '.mp3';
var sound1 = new buzz.sound(sPath);
sound1.play().bind('ended', function(e){
//here i want sound1 to finish before sound2 plays and so forth
});
}
How can i wait until sound1 has finished before sound2 starts playing in a dynamic way ?
Upvotes: 2
Views: 1695
Reputation: 108
Probably not the most elegant solution, buzz allows you to define groups that you could use instead of an array but:
Try adding all of the files that you want to play to an array, then loop through said array binding an ended event to each element that triggers the next song to play.
An extremely simple example:
var files = [new buzz.sound('audio1.mp3'), new buzz.sound('audio2.mp3'), new buzz.sound('audio3.mp3')];
files.forEach(function(element, index) {
element.bind('ended', function(e) { // when current file ends
files[index+1].play(); // trigger the next file to play
});
})
files[0].play(); // start the first file that triggers the rest
Upvotes: 3