Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 have:

var ClickDown = $('#clickdown-wav')[0];

$(document).delegate('a','click',function() {
    ClickDown.play();
});

The problem is that it's not too snappy (on an iPad) as I press anchor tags. There is a noticeable lag between the time I press the anchor tag and the wav file plays.

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

like image 286
Phillip Senn Avatar asked Feb 23 '12 18:02

Phillip Senn


1 Answers

On iOS, there is no preloading. This was done by Apple on purpose, so that the user wouldn't have to use unnecessary bandwidth.

like image 90
Justice Erolin Avatar answered Oct 19 '22 12:10

Justice Erolin