Loop audio JavaScript code example
Example 1: how to loop audio in js
myAudio = new Audio('someSound.ogg');
if (typeof myAudio.loop == 'boolean')
{
myAudio.loop = true;
}
else
{
myAudio.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
}
myAudio.play();
Example 2: javascript loop audio list
let audio = new Audio();
var playlist = this.state.sequence;
audio.src = playlist[0].src;
audio.play();
audio.addEventListener('ended', function(){
}, true);
audio.loop = false;