SoundManager 2 Basic Examples

Wondering where to start? The following are some simple examples showing how to get started with SoundManager 2.

Keep in mind these methods will not be available until soundManager.onload() fires. The initialization time for SM2 seems to vary across browsers/platforms, so this method is called with a delay after window.onload() to be safe.

eg.

soundManager.onload = function() {
// soundManager is ready to use - createSound() / play() etc. can now be called
}

Demo 1a: Create + play (shortcut method)

soundManager.play('mySound0','../mpc/audio/AMB_SN_5.mp3');

Creates and plays a sound with ID "mySound0", at the specified URL. The sound can then be referenced by that ID later, eg. soundManager.play('mySound0');

Note that this method is only provided for convenience, and allows only ID and URL as parameters. If you want to specify other options (volume, loop, event handlers), you must use the object literal syntax as given below.

This will play an existing sound (created in-page), and uses the "onfinish" handler to make a call to play a second, pre-existing sound.

Bug note: Running this demo will change the way "aDrumSound" plays in Demo 3 as an onfinish handler is set here (ie., running demo 3 will also include the "aSymbalSound" sound after running this one.) When set via .play(), this behaviour should only apply to this .play() instance, but does not currently.