Sound Class
Acts as a wrapper for SoundJS as well as adding lots of other functionality for managing sounds.
Item Index
Methods
- _getSoundInst
- _markLoaded
- _onSoundComplete
- _playAfterload
- _poolinst
- _stopInst
- _stopSound
- _update
- createPreloadTask
- destroy
- exists
- fadeIn
- fadeOut
- init static
- isLoaded
- isLoading
- isPlaying
- isUnloaded
- loadConfig
- pauseAll
- pauseSound
- play
- preload
- preloadSound
- setContextMute
- setContextVolume
- stop
- stopContext
- unload
- unpauseAll
- unpauseSound
Properties
- _contexts
- _playAfterLoadBound
- _pool
- _sounds
- instance static
- supportedSound
- UNHANDLED static
Methods
_getSoundInst
-
channel
-
id
Gets a SoundInst, from the pool if available or maks a new one if not.
Parameters:
-
channel
createjs.SoundInstanceA createjs SoundInstance to initialize the object with.
-
id
StringThe alias of the sound that is going to be used.
Returns:
The SoundInst 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.
Parameters:
-
inst
SoundInstThe SoundInst that is complete.s
_playAfterload
-
alias
Plays a sound after it finishes loading.
Parameters:
-
alias
StringThe sound to play.
_poolinst
-
inst
Places a SoundInst back in the pool for reuse.
Parameters:
-
inst
SoundInstThe instance to repool.
_stopInst
-
inst
Stops and repools a specific SoundInst.
Parameters:
-
inst
SoundInstThe SoundInst to stop.
_stopSound
-
s
Stops all playing SoundInsts for a sound.
Parameters:
-
s
ObjectThe sound (from the _sounds dictionary) to stop.
_update
-
elapsed
The update call, used for fading sounds. This is bound to the instance of Sound
Parameters:
-
elapsed
IntThe time elapsed since the previous frame, in milliseconds.
createPreloadTask
-
id
-
list
-
callback
Creates a Task for the CloudKid Task library for preloading a list of sounds. This function will not work if the Task library was not loaded before the Sound library.
Parameters:
Returns:
A task to load up all of the sounds in the list.
destroy
()
public
Destroys cloudkid.Sound. This does not unload loaded sounds, destroy SoundJS to do that.
exists
-
alias
If a sound exists in the list of recognized sounds.
Parameters:
-
alias
StringThe alias of the sound to look for.
Returns:
true if the sound exists, false otherwise.
fadeIn
-
aliasOrInst
-
duration
-
targetVol
-
startVol
Fades a sound from 0 to a specified volume.
Parameters:
-
aliasOrInst
String | SoundInstThe alias of the sound to fade the last played instance of, or an instance returned from play().
-
duration
NumberThe duration in milliseconds to fade for. The default is 500ms.
-
targetVol
NumberThe volume to fade to. The default is the sound's default volume.
-
startVol
NumberThe volume to start from. The default is 0.
fadeOut
-
aliasOrInst
-
duration
-
targetVol
-
startVol
Fades a sound from the current volume to a specified volume. A sound that ends at 0 volume is stopped after the fade.
Parameters:
-
aliasOrInst
String | SoundInstThe alias of the sound to fade the last played instance of, or an instance returned from play().
-
duration
NumberThe duration in milliseconds to fade for. The default is 500ms.
-
targetVol
NumberThe volume to fade to. The default is 0.
-
startVol
NumberThe volume to fade from. The default is the current volume.
init
-
pluginOrder
-
filetypeOrder
-
completeCallback
Initializes the Sound singleton. If using createjs.FlashPlugin, you will be responsible for setting createjs.FlashPlugin.BASE_PATH.
Parameters:
isLoaded
-
alias
If a sound is loaded.
Parameters:
-
alias
StringThe alias of the sound to look for.
Returns:
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
Parameters:
-
alias
StringThe alias of the sound to look for.
Returns:
true if the sound is currently loading, false if it is loaded, unloaded, or does not exist.
isPlaying
-
alias
If a sound is playing.
Parameters:
-
alias
StringThe alias of the sound to look for.
Returns:
true if the sound is currently playing or loading with an intent to play, false if it is not playing or does not exist.
isUnloaded
-
alias
If a sound is unloaded.
Parameters:
-
alias
StringThe alias of the sound to look for.
Returns:
true if the sound is unloaded, false if it is loaded, loading or does not exist.
loadConfig
-
config
-
defaultContext
Loads a config object. This should not be called until after Sound.init() is complete.
pauseAll
()
public
Pauses all sounds.
pauseSound
-
alias
Pauses a specific sound.
Parameters:
-
alias
StringThe alias of the sound to pause. Internally, this can also be the object from the _sounds dictionary directly.
play
-
alias
-
completeCallback
-
startCallback
-
interrupt
-
delay
-
offset
-
loop
-
volume
-
pan
Plays a sound.
Parameters:
-
alias
StringThe alias of the sound to play.
-
completeCallback
FunctionAn optional function to call when the sound is finished. Passing cloudkid.Sound.UNHANDLED results in cloudkid.Sound not handling the sound and merely returning what SoundJS returns from its play() call.
-
startCallback
FunctionAn 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
BoolIf the sound should interrupt previous sounds (SoundJS parameter). Default is false.
-
delay
NumberThe delay to play the sound at in milliseconds(SoundJS parameter). Default is 0.
-
offset
NumberThe offset into the sound to play in milliseconds(SoundJS parameter). Default is 0.
-
loop
IntHow many times the sound should loop. Use -1 (or true) for infinite loops (SoundJS parameter). Default is no looping.
-
volume
NumberThe volume to play the sound at (0 to 1). Omit to use the default for the sound.
-
pan
NumberThe panning to start the sound at (-1 to 1). Default is centered (0).
Returns:
An internal SoundInst object that can be used for fading in/out as well as pausing and getting the sound's current position.
preload
-
list
-
callback
Preloads a list of sounds.
preloadSound
-
alias
-
callback
Preloads a specific sound.
setContextMute
-
context
-
muted
Sets mute status of all sounds in a context
Parameters:
-
context
StringThe name of the context to modify.
-
muted
BoolIf the context should be muted.
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.
Parameters:
-
alias
StringThe alias of the sound to stop.
stopContext
-
context
Stops all sounds in a given context.
Parameters:
-
context
StringThe name of the context to stop.
unload
-
list
Unloads a list of sounds to reclaim memory if possible. If the sounds are playing, they are stopped.
Parameters:
-
list
ArrayAn array of sound aliases to unload.
unpauseAll
()
public
Unpauses all sounds.
unpauseSound
-
alias
Unpauses a specific sound.
Parameters:
-
alias
StringThe alias of the sound to pause. Internally, this can also be the object from the _sounds dictionary directly.