N
N
nomta2017-06-18 19:38:26
JavaScript
nomta, 2017-06-18 19:38:26

How do I make a playlist start playing another track when one track ends?

There is a playlist consisting of audio elements, I create a collection of them, assign an eventListener by iteration:

var audios = document.getElementsByTagName('audio'), i = 0, len = audios.length;
for (; i < len; i++) {
  audios[i].addEventListener('ended', function() {
    audios[i + 1].playing();
  });
}
but this code doesn't work, no event handler is added. What could be wrong here? Or should the task be handled in some other way?
Judging by the console, a collection of audio elements is created, as expected, but without event handlers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sklyarov, 2017-06-18
@0example

for (; i < len; i++)
You have before ; it must be declared from which number i to start the loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question