Acts as a wrapper for SoundJS as well as adding lots of other functionality for managing sounds.
_getSoundInst
channel
id
Gets a SoundInstance, from the pool if available or maks a new one if not.
channel
createjs.SoundInstance
A createjs SoundInstance to initialize the object with.
id
String
The alias of the sound that is going to be used.
The SoundInstance that is ready to use.
_markLoaded
alias
callback
Marks a sound as loaded. If it needs to play after the load, then it is played.
_onSoundComplete
inst
The callback used for when a sound instance is complete.
inst
SoundInstance
The SoundInstance that is complete.s
_playEmpty
Satisfies the iOS event needed to initialize the audio Note that we listen on touchend as per http://www.holovaty.com/writing/ios9-web-audio/
_poolinst
inst
Places a SoundInstance back in the pool for reuse.
inst
SoundInstance
The instance to repool.
_stopInst
inst
Stops and repools a specific SoundInstance.
inst
SoundInstance
The SoundInstance to stop.
_stopSound
s
Stops all playing SoundInstances for a sound.
s
Object
The sound (from the _sounds dictionary) to stop.
_update
elapsed
The update call, used for fading sounds. This is bound to the instance of Sound
elapsed
Int
The time elapsed since the previous frame, in milliseconds.
addContext
config
Loads a context config object. This should not be called until after Sound.init() is complete.
config
Object
The config to load.
[context]
String
optional
The optional sound context to load sounds into unless otherwise specified by the individual sound. Sounds do not require a context.
[path=""]
String
optional
The path to prepend to all sound source urls in this config.
[preload=false]
Boolean
optional
Option to preload all sound files in this context..
sounds
Array
The list of sounds, either as String ids or Objects with settings.
listItem
Object | String
listItem.id
String
[listItem.src]
String
optional
[listItem.volume=1]
Number
optional
[listItem.loop=false]
Boolean
optional
[listItem.context]
String
optional
[listItem.preload]
Boolean
optional
The sound object for chaining
contextExists
context
If a context exists
context
String
The name of context to look for.
true if the context exists, false otherwise.
exists
alias
If a sound exists in the list of recognized sounds.
alias
String
The alias of the sound to look for.
true if the sound exists, false otherwise.
fadeIn
aliasOrInst
[duration=500]
[targetVol]
[startVol=0]
Fades a sound from 0 to a specified volume.
aliasOrInst
String | SoundInstance
The alias of the sound to fade the last played instance of, or an instance returned from play().
[duration=500]
Number
optional
The duration in milliseconds to fade for. The default is 500ms.
[targetVol]
Number
optional
The volume to fade to. The default is the sound's default volume.
[startVol=0]
Number
optional
The volume to start from. The default is 0.
fadeOut
aliasOrInst
[duration=500]
[targetVol=0]
[startVol]
[stopAtEnd]
Fades a sound from the current volume to a specified volume. A sound that ends at 0 volume is stopped after the fade.
aliasOrInst
String | SoundInstance
The alias of the sound to fade the last played instance of, or an instance returned from play().
[duration=500]
Number
optional
The duration in milliseconds to fade for. The default is 500ms.
[targetVol=0]
Number
optional
The volume to fade to. The default is 0.
[startVol]
Number
optional
The volume to fade from. The default is the current volume.
[stopAtEnd]
Boolean
optional
If the sound should be stopped when the fade completes. The default is to stop it if the fade completes at a volume of 0.
getDuration
alias
Gets the duration of a sound in milliseconds, if it has been loaded.
alias
String
The alias of the sound to look for.
The duration of the sound in milliseconds. If the sound has not been loaded, 0 is returned. If no sound exists by that alias, null is returned.
has
name
[callback]
Checks if the EventDispatcher has a specific listener or any listener for a given event.
If the EventDispatcher has the specified listener.
init
options
Initializes the Sound singleton. If using createjs.FlashAudioPlugin, you will be responsible for setting createjs.FlashAudioPlugin.BASE_PATH.
options
Object | Function
Either the options object or the ready function
[plugins=createjs.WebAudioPlugin,createjs.FlashAudioPlugin]
Array
optional
The SoundJS plugins to pass to createjs.Sound.registerPlugins().
[types=['ogg','mp3']]
Array
optional
The order in which file types are preferred, where "ogg" becomes a ".ogg" extension on all sound file urls.
[swfPath='assets/swfs/']
String
optional
The required path to the createjs.FlashAudioPlugin SWF
[ready]
Function
optional
A function to call when initialization is complete.
The new instance of the sound object
isLoaded
alias
If a sound is loaded.
alias
String
The alias of the sound to look for.
true if the sound is loaded, false if it is not loaded or does not exist.
isLoading
alias
If a sound is in the process of being loaded
alias
String
The alias of the sound to look for.
A value of true if the sound is currently loading, false if it is loaded, unloaded, or does not exist.
isUnloaded
alias
If a sound is unloaded.
alias
String
The alias of the sound to look for.
true if the sound is unloaded, false if it is loaded, loading, or does not exist.
linkContexts
parent
subContext
Links one or more sound contexts to another in a parent-child relationship, so that the children can be controlled separately, but still be affected by setContextMute(), stopContext(), pauseContext(), etc on the parent. Note that sub-contexts are not currently affected by setContextVolume().
true if the sound exists, false otherwise.
loadConfig
config
Add a configuration to the load, see addContext
config
Object
The configuration
Sound object for chaining
off
name
callback
Remove the event listener
Return this EventDispatcher for chaining calls.
on
name
callback
[priority=0]
Add an event listener. The parameters for the listener functions depend on the event.
name
String | Object
The type of event (can be multiple events separated by spaces), or a map of events to handlers
callback
Function | Array*
The callback function when event is fired or an array of callbacks.
[priority=0]
Int
optional
The priority of the event listener. Higher numbers are handled first.
Return this EventDispatcher for chaining calls.
once
name
callback
[priority=0]
Add an event listener but only handle it one time.
name
String | Object
The type of event (can be multiple events separated by spaces), or a map of events to handlers
callback
Function | Array*
The callback function when event is fired or an array of callbacks.
[priority=0]
Int
optional
The priority of the event listener. Higher numbers are handled first.
Return this EventDispatcher for chaining calls.
pause
alias
Pauses a specific sound.
alias
String
The alias of the sound to pause. Internally, this can also be the object from the _sounds dictionary directly.
pauseContext
context
Pauses all sounds in a given context. Audio paused this way will not be resumed with resumeAll(), but must be resumed individually or with resumeContext().
context
String
The name of the context to pause.
pauseContext
context
Resumes all sounds in a given context.
context
String
The name of the context to pause.
pauseSound
alias
Unpauses a specific sound, see pause
alias
String
The alias of the sound to pause.
play
alias
[options]
Plays a sound.
alias
String
The alias of the sound to play.
[options]
Object | Function
optional
The object of optional parameters or complete callback function.
[complete]
Function
optional
An optional function to call when the sound is finished.
[start]
Function
optional
An optional function to call when the sound starts playback. If the sound is loaded, this is called immediately, if not, it calls when the sound is finished loading.
[interrupt=false]
Boolean
optional
If the sound should interrupt previous sounds (SoundJS parameter). Default is false.
[delay=0]
Number
optional
The delay to play the sound at in milliseconds (SoundJS parameter). Default is 0.
[offset=0]
Number
optional
The offset into the sound to play in milliseconds (SoundJS parameter). Default is 0.
[loop=0]
Int
optional
How many times the sound should loop. Use -1 (or true) for infinite loops (SoundJS parameter). Default is no looping.
[volume]
Number
optional
The volume to play the sound at (0 to 1). Omit to use the default for the sound.
[pan=0]
Number
optional
The panning to start the sound at (-1 to 1). Default is centered (0).
An internal SoundInstance object that can be used for fading in/out as well as pausing and getting the sound's current position.
resume
alias
Unpauses a specific sound.
alias
String
The alias of the sound to pause. Internally, this can also be the object from the _sounds dictionary directly.
resumeAll
Unpauses all sounds that were paused with pauseAll(). This does not unpause audio that was paused individually or with pauseContext().
setContextVolume
context
volume
Sets volume of a context. Individual sound volumes are multiplied by this value.
stop
alias
Stops all playing or loading instances of a given sound.
alias
String
The alias of the sound to stop.
stopContext
context
Stops all sounds in a given context.
context
String
The name of the context to stop.
trigger
type
arguments
Dispatch an event
type
String
The type of event to trigger
arguments
Additional parameters for the listener functions.
unload
list
Unloads a list of sounds to reclaim memory if possible. If the sounds are playing, they are stopped.
list
Array
An array of sound aliases to unload.
_sounds
Dictionary of sound objects, containing configuration info and playback objects.
isSupported
If sound is enabled. This will only be false if Sound was unable to initialize a SoundJS plugin.
preventDefaultOnUnmute
If preventDefault should be called on the interaction event that unmutes the audio. In most cases (games) you would want to leave this, but for a website you may want to disable it.
Default: true
systemMuted
If sound is currently muted by the system. This will only be true on iOS until audio has been unmuted during a touch event. Listen for the 'systemUnmuted' event on Sound to be notified when the audio is unmuted on iOS.