Computer >> Computer tutorials >  >> Programming >> Javascript

How to play HTML <audio> blocks one by one with no pops and clicks?


To play HTML <audio>blocks one by one, use the following HTML first −

<audio id = "one">
   <source src = "new1.mp3" type = "audio/mp3">
</audio >
<audio id = "two">
   <source src = "new2.mp3" type = "audio/mp3">
</audio >

The following is what you need to do to play audio one by one −

var one = document.getElementById('one');
one.onended = function() {
   document.getElementById('two').play();
}
one.play();