Html5 Audio plays only once in my Javascript code.

Posted by Poul on Stack Overflow See other posts from Stack Overflow or by Poul
Published on 2010-04-23T22:29:21Z Indexed on 2010/04/23 22:33 UTC
Read the original article Hit count: 310

Filed under:
|
|

I have a dashboard web-app that I want to play an alert sound if its having problems connecting. The site's ajax code will poll for data and throttle down its refresh rate if it can't connect. Once the server comes back up, the site will continue working.

In the mean time I would like a sound to play each time it can't connect (so I know to check the server). Here is that code. This code works.

var error_audio = new Audio("audio/"+settings.refresh.error_audio);
error_audio.load();

//this gets called when there is a connection error.
function onConnectionError() {
   error_audio.play();
}

However the 2nd time through the function the audio doesn't play. Digging around in Chrome's debugger the 'played' attribute in the audio element gets set to true. Setting it to false has no results. Any ideas?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html5