and then in my J...">

How to play sounds in JavaScript

I have the following:

<audio id="clickdown-wav" src="ClickDown.wav" preload="auto"></audio> 

and then in my JavaScript, I:

 var ClickDown = $('#clickdown-wav')[0]; $(document).delegate('a','click',function() { ClickDown.play(); }); 

The problem is that it is not too fast (on the iPad) when I click on the anchor tags. There is a noticeable time lag when I click on the anchor tag and the wav file is played.

Q: Is there only source code for playing sounds from JavaScript? Clickdown.wav is only 1k.

+6
source share
3 answers

There is no preload on iOS. This was done by Apple on purpose, so the user would not have to use unnecessary bandwidth.

+2
source

You can try putting an invisible "button" on top of your web application, which gets a click with the first user interaction. After that interaction sound.play(); should work. Look at this thread .

+1
source

you need to use touch events rather than click events, switch your click to "touchstart" and the delay will disappear.

+1
source

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


All Articles