7

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.

Phillip Senn
  • 46,771
  • 90
  • 257
  • 373

3 Answers3

2

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

Justice Erolin
  • 2,869
  • 20
  • 19
1

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

milkman
  • 11
  • 1
1

You can try to place an invisible "button" over your web app, which get's click with the first user interaction. After that interaction sound.play(); should work. Look at this thread.

Community
  • 1
  • 1
dom
  • 11,894
  • 10
  • 51
  • 74