Im trying to play a random audio file using howler.js and then reselect a different random file overtime it loops. I have it playing and looping but with the same file every time it loops. The only random selection is on initial load.
This is what I have:
var number = Math.floor((Math.random() * 3) + 1);
var sound1 = new Howl({
src: ['audio/'+number+'.wav'],
autoplay: false,
loop: false,
volume: 1.0,
onend: function() {
sound1.play()
}
});
sound1.play()
This happily plays one of 3 random wav files from audio folder but only selects randomly on load. The same file then loops infinitely.
Pretty new to javascript so any help appreciated. Thanks.
Aucun commentaire:
Enregistrer un commentaire