- Joined
- Dec 14, 2021
- Messages
- 28
- Reaction score
- 2
I have this code, it works fine, but it doesn't loop back to the first audio file.
As I said, it works, but when it gets to the end of the last audio file, it doesn't loop back to the first audio file.
So, how do I make it loop back to the first audio file?
JavaScript:
function autoPlayTrig() {
var aPT = document.getElementById("autoPlay");
if (aPT.innerHTML == "no") {
CurAudio.play();
aPT.innerHTML = "yes";
playBTNlock("yes");
CurAudio.onended = function() {
if (curSetTrack == trackNum) {
curSetTrack = 0;
CurAudio.src = trackArray[curSetTrack].split("||")[0];
nt.innerHTML = trackArray[curSetTrack].split("||")[1];
tkLan.innerHTML = trackArray[curSetTrack].split("||")[2];
ttn.innerHTML = curSetTrack;
CurAudio.play();
} else {
curSetTrack += 1;
CurAudio.src = trackArray[curSetTrack].split("||")[0];
nt.innerHTML = trackArray[curSetTrack].split("||")[1];
tkLan.innerHTML = trackArray[curSetTrack].split("||")[2];
ttn.innerHTML = curSetTrack;
CurAudio.play();
}
}
} else if (aPT.innerHTML == "yes") {
CurAudio.pause();
aPT.innerHTML = "no";
playBTNlock("no");
}
}
As I said, it works, but when it gets to the end of the last audio file, it doesn't loop back to the first audio file.
CurAudio
is the audio tag in the HTML.nt
is the name of the audio file.tkLan
is the length of the audio file.ttn
is the position the audio file is in the playlist.trackArray
is the array where all audio files and necessary data of them are held.playBTNlock
is the function that says whether or not the normal play button is disabled.So, how do I make it loop back to the first audio file?