Add playalbum.js.
This commit is contained in:
parent
638b466835
commit
0e5bb9881d
1 changed files with 20 additions and 0 deletions
20
Javascript/playalbum.js
Normal file
20
Javascript/playalbum.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
javascript:
|
||||||
|
|
||||||
|
function give_event(player, index)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
This needs to be a function instead of inlined into the loop because `next`
|
||||||
|
needs to be scoped, otherwise all of the players share the same next
|
||||||
|
variable and it doesn't work.
|
||||||
|
*/
|
||||||
|
var next = index + 1;
|
||||||
|
players[index].addEventListener("ended", function(){ console.log(next); players[next].play(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
players = document.getElementsByTagName("audio");
|
||||||
|
/*length - 1 because the final player doesn't need an event, only the second-last.*/
|
||||||
|
for (var index = 0; index < players.length - 1; index += 1)
|
||||||
|
{
|
||||||
|
give_event(players[index], index);
|
||||||
|
}
|
||||||
|
players[0].play();
|
Loading…
Reference in a new issue