API Documentation for: 0.5.1
Show:

SoundJS Module

Defined in: SoundJS:8

The SoundJS library manages the playback of audio on the web. It works via plugins which abstract the actual audio implementation, so playback is possible on any platform without specific knowledge of what mechanisms are necessary to play sounds.

To use SoundJS, use the public API on the Sound class. This API is for:

  • Installing audio playback Plugins
  • Registering (and preloading) sounds
  • Creating and playing sounds
  • Master volume, mute, and stop controls for all sounds at once

Please note that as of version 0.4.0, the "SoundJS" object only provides version information. All APIs from SoundJS are now available on the Sound class.

Controlling Sounds
Playing sounds creates SoundInstance instances, which can be controlled individually.

  • Pause, resume, seek, and stop sounds
  • Control a sound's volume, mute, and pan
  • Listen for events on sound instances to get notified when they finish, loop, or fail

Feature Set Example

 createjs.Sound.addEventListener("fileload", createjs.proxy(this.loadHandler, this));
 createjs.Sound.registerSound("path/to/mySound.mp3|path/to/mySound.ogg", "sound");
 function loadHandler(event) {
     // This is fired for each sound that is registered.
     var instance = createjs.Sound.play("sound");  // play using id.  Could also use full sourcepath or event.src.
     instance.addEventListener("complete", createjs.proxy(this.handleComplete, this));
     instance.volume = 0.5;
 }

Browser Support

Audio will work in browsers which support HTMLAudioElement (http://caniuse.com/audio) or WebAudio (http://caniuse.com/audio-api). A Flash fallback can be added as well, which will work in any browser that supports the Flash player.