Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-platform, cross-browser way to play sound using jQuery 1.4?

Tags:

I'm trying to get jQuery to play a sound on element hover/click. (It's like a flash website without flash)

I've tried the methods recommended in Cross-platform, cross-browser way to play sound from Javascript?, the jQuery Sound plugin and a couple of other tutorials without any success. I'm assuming this is because they haven't been updated since 2008.

Does anyone have any recommendations?

like image 873
Erin Avatar asked May 04 '10 21:05

Erin


2 Answers

Don't need any of those. The HTML tag, combined with JavaScript, will do the trick.

<audio id="soundHandle" style="display: none;"></audio> <script>   soundHandle = document.getElementById('soundHandle');   soundHandle.src = '/blah/blah.mp3';   soundHandle.play(); </script> 
like image 180
Delan Azabani Avatar answered Sep 21 '22 20:09

Delan Azabani


Actually it's impossible to do in a truly cross-browser compliant way as for example iPhones will play sound only on a dedicated player "page". However some of the plugins in the other answers should do the job for most (desktop) browsers.

like image 29
Jakub Hampl Avatar answered Sep 20 '22 20:09

Jakub Hampl