Any idea how to get Chrome to play the sound again after a second click? Works just fine with Firefox:
<html>
<head>
<title>audiotest</title>
<SCRIPT language="JavaScript">
var snd = new Audio("img/meow0.ogg");
function test(){
if(snd.currentTime>0)
snd.currentTime=0;
console.log(snd.currentTime);//0 on firefox, initially 0 on chrome, then == snd.duration
snd.play();
}
</SCRIPT>
</head>
<body>
<a href="javascript:test();">test</a>
</body>
</html>
It happend in a webpage where I use to play chess. I lost many games because the bell didn’t ring on my turn 🙂 It irritated me so I tried to fix it, but found out it wasn’t a bug in the chess page (happend everywhere with HTML5 audio.)
This seems to be Chrome’s/Webkit’s fault. Searching for information I stumbled upon Chrome’s issue #25792 which may be related (many more if you search for chrome audio bug.) Apparently it was fixed in Chrome 17, but the Windows binary release of Chrome is 16. Upon audio freezing it will refuse to play any more files until browser restart.
EDIT: I just realized you stated your audio is never working on your second try, but the bug I pointed to happens randomly, not always. You might have to .pause() it after playback to get audio to work as expected.