For starters, you are attaching a new event handler every single time the element is clicked. If someone frequently pauses the music, they will run into problems.
Intead, try this:
<audio id="audio" autoplay controls src="song.php" type="audio/mpeg"></audio>
<script type="text/javascript">
document.getElementById('audio').addEventListener("ended",function() {
this.src = "song.php?nocache="+new Date().getTime();
this.play();
});
</script>
I'm assuming that song.php
is a PHP file that returns the audio data. The nocache
query parameter will ensure that the file is actually called every time.