From 68a92d895c30df66fbc5ddafa71d4626c9177766 Mon Sep 17 00:00:00 2001 From: Giulio De Matteis Date: Mon, 14 Dec 2020 00:40:14 +0100 Subject: [PATCH] Automatically start playing the first song after the last one --- player.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/player.html b/player.html index 12033a3..64bf549 100644 --- a/player.html +++ b/player.html @@ -80,11 +80,14 @@ }; player.addEventListener('ended', function () { - currentSong.style.fontWeight = 400; var index = parseInt(currentSong.getAttribute('index')) + 1; + currentSong.style.fontWeight = 400; + if(document.querySelector(`[index="${index}"]`) === null){ + index = 0; + } currentSong = document.querySelector(`[index="${index}"]`); - currentSong.style.fontWeight = 900; playerSource.src = tracksList['tracks'][index]['file']['mp3-128']; + currentSong.style.fontWeight = 900; player.load(); player.play(); }, false);