play audio on loop js code example
Example 1: play audio in javascript
var audio = new Audio('audio_file.mp3');
audio.play();
Example 2: 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();