Version 1.0.20041003a

 

January 2007: SM1 end of life notice

SoundManager ("V1") is no longer supported nor maintained. It has been deprecated in favour of SoundManager 2, which provides a highly-featured Javascript sound API via Flash 8 + ExternalInterface, better documentation and demos. Check it out.

Executive Summary

SoundManager is an object-oriented library/API which provides a Javascript interface to control sounds loaded in a hidden Flash movie.

A small Flash "stub" movie loads audio files with IDs as assigned by an external XML file. These sounds can then be controlled by the SoundManager Javascript API using predefined methods.

Basic Use

A sound is loaded into the Flash stub movie via XML such as: <sound id="mySound" href="soundfile.mp3" />

This sound can then be played via the following Javascript: soundManager.play('mySound');

Refer to the test controls at right, or hit this simplified example page for a basic demo.

Download

Soundmanager v1.0.20041003a (108 KB, .ZIP)

Free for use. Questions, comments, complaints etc. can be sent via e-mail (see Credits)

Supported Methods

The following methods are defined under SoundManager:

play(soundID,loopCount)
Plays the sound as specified by soundID, loopCount times.
Parameters:
  • soundID: ID of the sound to be played, as defined in the XML configuration file.
  • loopCount: Number of times (default=1) to play the sound.
Example: soundManager.play('mySound');
stop(soundID)
Stops the sound as specified by soundID.
Parameters:
  • soundID: ID of sound as defined in XML
Example: soundManager.stop('mySound');
setPan(soundID,pan)
Sets the pan of sound soundID.
Paramaters:
  • soundID: ID of sound as defined in XML
  • pan: Integer from -100 to 100
Example: soundManager.setPan('mySound',-25);
setVolume(soundID,volume)
Sets the volume of sound soundID.
Paramaters:
  • soundID: ID of sound as defined in XML
  • volume: Integer from 0 to 100
Example: soundManager.setVolume('mySound',75);

Implementation

A script include is required for the SoundManager API. A single Flash movie (.swf) provides the stub for loading sounds, and an XML file defines the sounds to be loaded and their corresponding IDs referenced within the API calls.

Requirements

This functionality requires a browser with Javascript and Flash 6 support, and support for Javascript-to-Flash plug-in communication (see Macromedia's "Scripting with Flash" page for exact version and platform details.)

Testing has been done on the following:

Known Issues

Seamless Looping

According to Macromedia, looping of imported MP3 audio is not seamless. (D'oh.)

Mac Platform

It appears that Javascript-to-Flash communication is not supported under ie:Mac due to the way the plug-in is compiled for the OS, so this type of scripted sound is not possible on this platform. Interestingly enough, it has been reported to work under Mozilla Firefox on Linux.

Opera

A mysterious beast at best, likely on the "unsupported" list in terms of JS-to-Flash communication.

Resources

Technical Information

Sound Object Reference - Actionscript.org

Macromedia TechNotes: "Why do my looping sounds pause between loops?

Sound Effects Tutorial (Dynamic MP3 loading via XML) - Sitepoint.com

Related Works

Sonify.org FlashSound API

The inspiration source for my initial experiments with JS-to-Flash communication back in 2001. Now a bit dated (and not compatible with Mozilla,) but still a good reference.

Credits

Code by Scott Schiller.

Schillmania.com: Personal experimental DHTML site

Scottschiller.com: Professional and technical experience portfolio

Test Sounds

Click the buttons below to hear the related sound. Each button makes a call to soundManager.play(soundID) when clicked, where soundID is a unique identifier assigned to a sound (eg. an MP3) in the configuration XML file.

Sound Controls

Basics

Pan

Volume

Error Handling

Invalid Sound ID Tests When a method is called on a sound whose ID is not defined in the flash XML file, an exception is thrown. Click the below for examples; this information can be helpful when debugging your own work.

Note that this only seems to work under IE:win32 for some reason.

Stress Tests

Simultaneous Calls Test playing a sound a given number of times. This may help to determine how to avoid potential crashes.

Debugger Output