Last week I read about the SoundManager2 javascript/flash library to manage sounds on websites (I found SoundManager2 while reading about MooSound, a sound management library based in Mootools that I haven’t tried yet.). The library looks very nice. It is pretty small but at the same time it gives you a lot of control on sound playing. You can change the position of the sound while playing, adjust the stereo pan from left to right and much more.
Today I wanted to test this library and I decided to add some sounds to my Particle-Balls demo. Every time a ball hits a wall, a sound plays. To make it more fun, I use the X coordinate of the ball to adjust the pan, so if the ball is closest to he left border the sound will play on the left speaker and same with the right border/speaker. The pan can be adjusted gradually from -100 to 100 (left to right).

Check the demo here:
http://dev.enekoalonso.com/research/particle-balls.php

The problem with the javascript/flash library is that under some environments there is a delay between the action and the sound (for example, I’ve tried the demo on FF3/Ubuntu, and the balls hitted the wall but the sound came after a second or so).
Check Demonstration of Different Ways to Play a Sound from a Web Page to see different ways to play sounds using javascript.
I like the 4th method, although I remember only WAV files will work on all browsers using this method, which is unlikely. The great advantage of using flash is that it can play MP3, and you can create good controls for using javascript (SoundManager2 is great).
Thanks for the link Pau. I didn’t know there where so many ways of playing sounds from Javascript on a browser.
The only issues I see on those methods are:
1. They are very intrusive (you need to put all sounds you are going to use in the HTML code or add the DOM elements on the fly).
2. I think it would be very hard to play multiple sounds at the same time (check out the forest demo), not to say the same sound playing more than once (for example if a ball hits the wall while the sound from a previous hit is still playing).
I have to investigate the performance issues with the flash solution. It may be something from flash or it may be a problem with the SoundManager2 library. Do you know any flash alternatives?
Thanks :)
Some time ago I was researching and playing with all of this stuff, and at the end my conclussion was that SoundManager2 is the best solution out there for playing sounds in browsers. In fact I used it on my development version of Artypist (not yet released).
I don’t know of any other library that works as great as SoundManager2. It gives you great control over sounds being played and it is quite clean.
I just wanted to point out other methods on the previous comment ;)