0

I want to loop through the same audio that I have, but it seems like it sometimes work, and sometimes doesn't, and sometimes it only sound part of the times he supposed to,

Is there a reliable way to ensure of playing the sound? and so it won't go to the next iteration of the for loop until it finishes the sound?

That's the mainly code I have:

for(var i = 0; i < 10; i++)
{
    setTimeout(function () {
        document.getElementById("hitSound").play();
    }, 500*i);
}

edit: another problem:

Sometimes it doesn't play the audio at all, which is a bit strange, is there a way to call a func when the audio is finished? just to make sure it was played already?

I also tried this code:

myAudio = new Audio('someSound.ogg');
myAudio.loop = true;
myAudio.play();
Dorki
  • 1,021
  • 2
  • 8
  • 23

0 Answers0