Html5 Audio plays only once in Javascript code

I have a dashboard web application that I want to play a beep if it has a connection problem. The site’s adax code will be polled for data and will reduce its refresh rate if it cannot connect. After the server is restored, the site will continue to work.

At the same time, I would like the sound to play every time it cannot connect (so I know to check the server). Here is the 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 second time no sound is played through the function. Digging in the Chrome debugger, the attribute "played" in the audio element is set to true. Setting it to false has no results. Any ideas?

+3
6

Chrome/Safari , , . , .

0

, , source , . , , .

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.src = "audio/"+settings.refresh.error_audio;
   error_audio.play();
}

21. FF, , src!

+3

error_audio.currentTime 0 . ,

+1

Q: IVE , (), , () ! !

A: node , . , AudioBufferSourceNode noteOn().

node , . , AudioBuffer, , . , , playSound (buffer).

Q: , node ?

A: , . , . , , .

:

http://updates.html5rocks.com/2012/01/Web-Audio-FAQ

+1

, . Javascript/Jquery - HTML5 - - How to handle/control the HTML5 audio elements?. !

+1

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

See here: HTML5 <audio> Live Safari vs not

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

0
source

Source: https://habr.com/ru/post/1742540/


All Articles