When working on an upcoming project I had the need to play sound through JavaScript. The method had to be cross-browser compatible, so I couldn't use any IE only calls.
Happily, I found a nice API called SoundManager2 which uses Flash to play the sound and is called through JavaScript. The API is very easy to use and below is a sample of how to use it.

The below code would be put inside the head tag of your web page.
<script type="text/javascript" src="soundmanager2-jsmin.js"></script> <script type="text/javascript"> soundManager.url = 'soundmanager2.swf'; // override default SWF url soundManager.debugMode = false; soundManager.consoleOnly = false; soundManager.onload = function() { // soundManager is initialised, ready to use. Create a sound for this demo page. soundManager.createSound('aDrumSound','button-0.mp3'); }</script>
The part of the above code that you will be most interested in is the last line. The soundManager.createSound('aDrumSound','button-0.mp3'); is what actually loads the sound file.
The below code will cause the sound to play.
soundManager.play('aDrumSound');
You can go to the project page by clicking here and get more information about the API. Also, you can download the files needed to use the API (including documentation and demos) here.
The library would be very useful in many applications including JavaScript games. If you create any cool applications using the API I would love to hear about it. You can post a blog entry about it when you create a free account (once you login just click on "Create content" => "Blog Entry") on this blog.
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket
Recent comments
3 days 25 min ago
3 days 3 hours ago
3 days 11 hours ago
4 days 4 hours ago
4 days 7 hours ago
1 week 15 hours ago
1 week 17 hours ago
1 week 2 days ago
1 week 4 days ago
1 week 4 days ago