I'm trying to make an MP3 random player. I've already done every array and cycles, but what it struggles me is that every songs plays all in the same time, basically something like that:
var num; var x = 0; let music = ['https://samplelib.com/lib/previeww/mp3'sample-3s.mp3', 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3']; funcion button(){ for (let i = 0; i < 4; i++){ num = Math.floor(Math.random()*3);
console.log(num);} music.play(num)} music[num].addEventListener('ended', console.log("placeholder")});
What happens, as I porevious said before, the cycle doesn't wait the sound to finish, it goes back over and over again until the page crashes. Is there any way to make him wait before it plays again?