Monday, January 29th, 2007
SoundManager 2: A Sound API for JavaScript
Scott Schiller has come up with something very useful: SoundManager 2 a sound API which lets web developers easily load, play and control
sounds (via Flash 8) using Javascript.
Scott talks about his back story to how this API came about, for the jsAMP program.
There is a full project page with API documentation, some nifty examples and
demos, and a download (BSD license) here.
He also has a number of nifty demos for us to check out:
- Basic in-page API examples with code (onload, createSound, play etc.)
- An MPC (sampler/drum machine) demo, showing some of the basic sound event
handlers (loading, play position/progress and so on) - The reason I did this in the first place: jsAMP, an in-page MP3 player (inspired by Winamp) which uses the SM2 API
Check it out and give Scott some feedback.













Good library. I tried it a few weeks ago, and got it up and running very quickly.
But we have flashsoundapi.com already… and they have some cool samples as well… why another api? What’s the difference? (Is it easier to create the flash files for a flashturkey like me?)
ref: http://www.flashsoundapi.com/?preload=true
NICE! Been looking for something like this for a long time.
This one has been out longer than flashsoundapi i believe. Various versions at least. So why do we need flashsoundapi when we have this one. Why have JQuery if we have Prototype ahah
there is no flash file, you have the swf with it, i think.
Marc: Thanks for the link, I don’t think I’ve ever seen that one before.
One of the differences with SM2 is that you don’t have to understand how to build Flash, nor build your own movies to load or embed sounds – it’s all handled in Javascript, and you can load MP3s directly from any URL. I’m not much of a Flash person myself, and wanted a convenient way to do things with sound, but from the familiar JS environment.
Scott! Way to go…
You should see if you can adapt a shim for the HTML5 Audio interface (which Opera 9 supports, btw).
are you guys bros?
We’re related – cousins.
Thanks for the HTML 5 tip also, I’ll have to keep an eye out. Opera seems to be ahead of the curve on some proposed and upcoming standards.
Great! this is going to be useful for music pages.
Hi Scott: “you don’t have to understand how to build Flash” now that’s what I like to hear! I’m not a flash person too…
I don’t have much time to check out your library but am curious how the reaction times are in the sense of click and play or click, wait a millisecond, and play. In games this can be very important.
It’s a really nice API which is very easy to get up and working. It still contains a few bugs but with the help from the community those will easily be sorted out!
Marc: Without preloading anything it’s very fast when I’ve tested it, can’t imagine how fast it might be if you preload the sounds. He has a demonstration of a “game” on his site: http://www.schillmania.com/projects/soundmanager2/demo/animation/
There is actually a delay which can vary across systems from what I’ve seen, and I suspect it’s due to the way Adobe write out some JS to make externalInterface work. My understanding is JS calls to Flash are serialised into XML which apparently uses eval() and other things before actually being passed to the movie, which I believe may be the cause of this delay. Brad Neuberg has done some really interesting research in this area.
Ironically, the older version of SoundManager doesn’t use ExternalInterface, and doesn’t have this kind of delay. I’d like to figure out a way around this, as it would be nice to have timing down for games, etc.
Scott, will your soundplayer play file types other than mp3? Such as sound-only swf, aif, wav, etc?
From what I’ve read, Flash 8’s native Sound.loadSound() only takes MP3s, presumably because (guessing here,) there’s only an MP3 decoder within the Flash plugin. You might be able to extend the code to load .swf files containing sound-only resources, but I imagine those are ultimately MP3-based as well.
I used the API for our company xmas card (http://www.turntool.com/tnt/xmas2006 (I know, it is very heavy on your cpu)) and found it a little buggy. Setting a default volume level was omitted as the file looped. Instead I had to set the volume at each loop.
Else it was nice and easy to use!
.Findorf
nice blog
Looking for mortgage?
I am really glad to finally see some kind of support for sound! I build web apps with JSF and Ajax, and see a lot of possibilities for the SoundManager2 api.
One specific need I have in an order entry scenario is to play a warning sound when a user enters an incorrect product number. They are usually entering these numbers in a “heads down†fashion, and need an audible warning so they will look up at the screen when a mistake has been made. But I can’t quite figure out how to call the javascript function to play the sound as a result of a method call to the java bean that backs my JSF page. When a product number is entered, the button click calls a bean method to validate the number and returns true if valid or false if invalid. How can I then use that return value from the bean to decide weather or not to call the javascript function to play the warning sound?
awsome website
Really.What do you know…A widget is always bound to an HTML element. This will typically be a div, but can really be anything (depending on the widget). We take the Dojo approach of leveraging custom attributes in order to do all of the wiring
Gee interesting… i need to go walk the dog..later bud!
Hi Reply to Mike , there was several hacks that you can do with your JSF trick ,
if the page submit is going to refresh the page.
and put outside the form so that the id will remain “play”
and then window.onload call a validate and see play or not …
if you wanna do ajax checkup to beans … try DWR . it has direct mapping from javascript to java beans … save your life a lot …
Hopes this will help you :)
I tried it a few weeks ago, and got it up and running very quickly.
- Daelen, designer of healthy eating for diabetes