Monday, January 29th, 2007

SoundManager 2: A Sound API for JavaScript

Category: JavaScript, Library, Sound

<p>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:

Check it out and give Scott some feedback.

Related Content:

20 Comments »

Comments feed TrackBack URI

Good library. I tried it a few weeks ago, and got it up and running very quickly.

Comment by Rufus — January 29, 2007

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

Comment by Marc — January 29, 2007

NICE! Been looking for something like this for a long time.

Comment by Aidan McQuay — January 29, 2007

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

Comment by JD — January 29, 2007

there is no flash file, you have the swf with it, i think.

Comment by JD — January 29, 2007

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.

Comment by Scott Schiller — January 29, 2007

Scott! Way to go…

You should see if you can adapt a shim for the HTML5 Audio interface (which Opera 9 supports, btw).

Comment by Jeff Schiller — January 29, 2007

are you guys bros?

Comment by JD — January 29, 2007

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.

Comment by Scott Schiller — January 29, 2007

Great! this is going to be useful for music pages.

Comment by Min Thu — January 30, 2007

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.

Comment by Marc — January 30, 2007

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/

Comment by Pelle — January 30, 2007

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.

Comment by Scott Schiller — January 30, 2007

Scott, will your soundplayer play file types other than mp3? Such as sound-only swf, aif, wav, etc?

Comment by Tom Trenka — January 31, 2007

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.

Comment by Scott Schiller — February 1, 2007

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

Comment by Johannes Findorf — February 4, 2007

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?

Comment by Mike — June 28, 2007

awsome website

Comment by music — September 10, 2007

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!

Comment by Friendly dog — October 6, 2007

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 :)

Comment by Adisonz — May 8, 2008

Leave a comment

You must be logged in to post a comment.