I have a function randomPlay
associated to event onended
but the random number is always the same on Firefox. On Chrome it's okay. Anyone can explains why and how to fix?
function randomPlay(){
$("audio").html('<source src="'+srcArray[Math.floor(Math.random() * srcArray.length)]+'" type="audio/mpeg">');
document.getElementById('audio').play();
}
The element is this audio:
<audio id="audio" autoplay onended="randomPlay();" ><source src="music.mp3" type="audio/mpeg"></audio>
UPDATE
I changed the element to:
<audio id="audio" autoplay onended="randonPlay();" src=""></audio>
and changed the function to:
function randonPlay(){
$("audio").attr("src",srcArray[Math.floor(Math.random() * srcArray.length)]);
document.getElementById('audio').play();
}
So all is fine now :) Thank You for your help all. Anyway I also found a lib to generate random numbers Chance.js