Tuesday, May 14, 2013

minimal soundmanager2 quickstart

I'm proud of lowLag.js but sometimes it's overkill when you just want the flexibility SoundManager2 provides. I think I've isolated the 2 files and boilerplate code you need to just play a sound.

Copies of the files are available here: one .js and the Flash fallback. (I admit I've had some problems trying to specify alternate locations for the Flash, so it's safest to put that file in the same directory as the page itself.) So put "soundmanager2.js" and "soundmanager2_debug.swf" in the folder as the file, add
<script src="soundmanager2.js"></script>
and then in add something like
    onready:sm2Ready ,
    debugMode: true,

function sm2Ready(){
        id: "asphault",
        autoLoad: true,
        url: "asphault.mp3"

function sm2play(){
That's it! You can see it in action. The code is a little complex because you need a callback to create the sounds after SM2 says it's ready. (There's also an "experimental feature" where the argument to url in createSound({}); can be an array of different files, if you're trying to support browsers that might not support every file format.)

(Of course for real work you should probably go to the SoundManager2 website and grab the latest files and read the documentation... this page is just for when you're in a hurry.)

No comments:

Post a Comment