I was trying to play a sound with javascript by using <audio> html5 tag. The sound played fine except it played only once. The solution was quite difficult to find.
In order to play a sound with javascript in Google Chrome, the audio file needs to be fetched from a server that supports Content-Range HTTP header. Otherwise, the browser won’t be able to determine the length of the sound and resetting audio tag’s currentTime property won’t work: it will always show the length of the sound, once played. The property behaved as if it were read-only. Calling .play() method again on the object won’t generate any sounds.
I got this problem because my simple web server in node.js didn’t support Content-Range header. Moving the audio (mp3, ogg, wav) files to an external web server (Apache or nginx) solved the problem and Chrome was able to play and replay the sounds.
A simple example:
<script> var a = new Audio(); a.src = 'url_of_the_file_to_play.ogg'; a.play(); </script>