Answers for "javascript new audio loop"

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();
Posted by: Guest on May-16-2020
0

javascript loop audio list

let audio = new Audio();
        var playlist = this.state.sequence; // load the sequence of sounds
        audio.src = playlist[0].src; // set the source of the first file in my array
        audio.play(); 
        // when the song ends, load the new sound
        audio.addEventListener('ended', function(){
            // increment playlist[i].src
        }, true);
        audio.loop = false;
Posted by: Guest on September-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language