I improved the answer a bit, so the opening song will start randomly and just remain in chronological order for the rest.
<script> var playlist = [ "music/bg1.mp3", "music/bg2.mp3", "music/bg3.mp3", "music/bg4.mp3" ]; var n = playlist.length-1; var r = 1 + Math.floor(Math.random() * n); $(document).ready(function() { var xA = document.getElementById("myAudio"); xA.volume = 0.3; xA.controls = true; function player(x) { var i = 0; xA.src = playlist[r]; xA.load(); xA.play(); xA.onended = function() { i++; if (i > n) { i = 0; } xA.src = playlist[i]; xA.load(); xA.play(); } } player(0); }); </script>
I thought about all the songs being repeated in random order, but I believe that I will need to make an array of numbers in order to count them or something like that. Still. it's just optional!
source share