0

Im trying to put one music to play after the previous one ended but for some reason my timer doesnt work and they all just start on top of one another not waiting the time it should

    var musics = [music1,music2,music3,music4,music5,music6]
    var musicas = shuffle(musics)
    var z = 0
    var timerr = 0
    function zz (){
        musicas[z].currentTime=0
        musicas[z].play()
            timerr = musicas[z].duration
        z++
        console.log(timerr)
    }
    setInterval(zz,timerr)

basically on this console.log it shows the duration of each music at the same time just one time for some reason so idk what im doing wrong

(javascript)

  • 1
    When you call `setInterval(zz,timerr)` you're passing 0 as the delay. I'd use the [`ended`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ended_event) event instead (setInterval won't work anyway because you cannot change the delay once the interval is running) –  Jun 01 '22 at 21:21
  • 1
    it seems to me that by [reading the doc](https://developer.mozilla.org/en-US/docs/Web/API/setInterval#delay_restrictions) you would not need to ask this question in this form – Mister Jojo Jun 01 '22 at 21:35
  • Does this answer your question? [HTML5 audio playlist - how to play a second audio file after the first has ended?](https://stackoverflow.com/questions/9326288/html5-audio-playlist-how-to-play-a-second-audio-file-after-the-first-has-ended) – Yogi Jun 01 '22 at 21:35

0 Answers0