views:

327

answers:

2

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?

A: 

Try setting error_audio.currentTime to 0 before playing it. Maybe it doesn't automatically go back to the beginning

Bob
In Chrome I get the following message when I add the currentTime line above. "Uncaught Error: INDEX_SIZE_ERR: DOM Exception". Any thoughts on this?
Poul
Has anyone else seen this exception in Chrome or gotten the above suggestion to work? Thanks!
Poul
A: 

You need to implement the Content-Range response headers, since Chrome requests the file in multiple parts via the Range HTTP header.

See here: http://stackoverflow.com/questions/1995589/html5-audio-safari-live-broadcast-vs-not/1995977#1995977

Once that has been implemented, both the play() function and setting the currentTime property should work.

TooTallNate