How to make the audio file play one song and play the next one directly?

I have an array. It contains the src address of the audio file

how to play the second audio file in the array directly after playing the first audio file

Mar.18,2021

use ended events

    var audio = document.getElementById("audio"); 
    audio.loop = false;
    audio.addEventListener('ended', function () {  
        //
    }, false);

<!DOCTYPE HTML>
<html>
<body>

<audio id="audio" controls="true" autoplay="true">
  <source src="/i/song.ogg" type="audio/ogg">
  <source src="/i/song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<script>
var audio = document.getElementById("audio"); 
audio.loop = false;
audio.addEventListener('ended', function () {  
    alert('over');
}, false);
</script> 
</body>
</html>
Rookie tutorial: http://www.runoob.com/tags/av.
Menu