API Documentation for: 3.0.0
Show:

Sound Class

Defined in: Sound:14
Namespace: cloudkid

Acts as a wrapper for SoundJS as well as adding lots of other functionality for managing sounds.

Methods

_getSoundInst

(
  • channel
  • id
)
SoundInst private

Defined in _getSoundInst:539

Gets a SoundInst, from the pool if available or maks a new one if not.

Parameters:

  • channel createjs.SoundInstance

    A createjs SoundInstance to initialize the object with.

  • id String

    The alias of the sound that is going to be used.

Returns:

SoundInst:

The SoundInst that is ready to use.

_markLoaded

(
  • alias
  • callback
)
private

Defined in _markLoaded:908

Marks a sound as loaded. If it needs to play after the load, then it is played.

Parameters:

  • alias String

    The alias of the sound to mark.

  • callback Function

    A function to call to show that the sound is loaded.

_onSoundComplete

(
  • inst
)
private

The callback used for when a sound instance is complete.

Parameters:

  • inst SoundInst

    The SoundInst that is complete.s

_playAfterload

(
  • alias
)
private

Defined in _playAfterload:564

Plays a sound after it finishes loading.

Parameters:

  • alias String

    The sound to play.

_poolinst

(
  • inst
)
private

Defined in _poolinst:972

Places a SoundInst back in the pool for reuse.

Parameters:

_stopInst

(
  • inst
)
private

Defined in _stopInst:672

Stops and repools a specific SoundInst.

Parameters:

_stopSound

(
  • s
)
private

Defined in _stopSound:656

Stops all playing SoundInsts for a sound.

Parameters:

  • s Object

    The sound (from the _sounds dictionary) to stop.

_update

(
  • elapsed
)
private

Defined in _update:365

The update call, used for fading sounds. This is bound to the instance of Sound

Parameters:

  • elapsed Int

    The time elapsed since the previous frame, in milliseconds.

createPreloadTask

(
  • id
  • list
  • callback
)
cloudkid.Task public

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:

  • id String

    The id of the task.

  • list Array

    An array of sound aliases to load.

  • callback Function

    The function to call when the task is complete.

Returns:

cloudkid.Task:

A task to load up all of the sounds in the list.

destroy

() public

Defined in destroy:990

Destroys cloudkid.Sound. This does not unload loaded sounds, destroy SoundJS to do that.

exists

(
  • alias
)
Bool public

Defined in exists:220

If a sound exists in the list of recognized sounds.

Parameters:

  • alias String

    The alias of the sound to look for.

Returns:

Bool:

true if the sound exists, false otherwise.

fadeIn

(
  • aliasOrInst
  • duration
  • targetVol
  • startVol
)
public

Defined in fadeIn:281

Fades a sound from 0 to a specified volume.

Parameters:

  • aliasOrInst String | SoundInst

    The alias of the sound to fade the last played instance of, or an instance returned from play().

  • duration Number

    The duration in milliseconds to fade for. The default is 500ms.

  • targetVol Number

    The volume to fade to. The default is the sound's default volume.

  • startVol Number

    The volume to start from. The default is 0.

fadeOut

(
  • aliasOrInst
  • duration
  • targetVol
  • startVol
)
public

Defined in fadeOut:320

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 | SoundInst

    The alias of the sound to fade the last played instance of, or an instance returned from play().

  • duration Number

    The duration in milliseconds to fade for. The default is 500ms.

  • targetVol Number

    The volume to fade to. The default is 0.

  • startVol Number

    The volume to fade from. The default is the current volume.

init

(
  • pluginOrder
  • filetypeOrder
  • completeCallback
)
static

Defined in init:91

Initializes the Sound singleton. If using createjs.FlashPlugin, you will be responsible for setting createjs.FlashPlugin.BASE_PATH.

Parameters:

  • pluginOrder Array

    The SoundJS plugins to pass to createjs.Sound.registerPlugins().

  • filetypeOrder Array

    The order in which file types are preferred, where "ogg" becomes a ".ogg" extension on all sound file urls.

  • completeCallback Function

    A function to call when initialization is complete.

isLoaded

(
  • alias
)
Bool public

Defined in isLoaded:244

If a sound is loaded.

Parameters:

  • alias String

    The alias of the sound to look for.

Returns:

Bool:

true if the sound is loaded, false if it is not loaded or does not exist.

isLoading

(
  • alias
)
Bool public

Defined in isLoading:256

If a sound is in the process of being loaded

Parameters:

  • alias String

    The alias of the sound to look for.

Returns:

Bool:

true if the sound is currently loading, false if it is loaded, unloaded, or does not exist.

isPlaying

(
  • alias
)
Bool public

Defined in isPlaying:268

If a sound is playing.

Parameters:

  • alias String

    The alias of the sound to look for.

Returns:

Bool:

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
)
Bool public

Defined in isUnloaded:232

If a sound is unloaded.

Parameters:

  • alias String

    The alias of the sound to look for.

Returns:

Bool:

true if the sound is unloaded, false if it is loaded, loading or does not exist.

loadConfig

(
  • config
  • defaultContext
)
public

Defined in loadConfig:178

Loads a config object. This should not be called until after Sound.init() is complete.

Parameters:

  • config Object

    The config to load.

  • defaultContext String

    The optional sound context to load sounds into unless otherwise specified. Sounds do not require a context.

pauseAll

() public

Defined in pauseAll:749

Pauses all sounds.

pauseSound

(
  • alias
)
public

Defined in pauseSound:708

Pauses a specific sound.

Parameters:

  • alias String

    The 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
)
SoundInst public

Defined in play:417

Plays a sound.

Parameters:

  • alias String

    The alias of the sound to play.

  • completeCallback Function

    An 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 Function

    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 Bool

    If the sound should interrupt previous sounds (SoundJS parameter). Default is false.

  • delay Number

    The delay to play the sound at in milliseconds(SoundJS parameter). Default is 0.

  • offset Number

    The offset into the sound to play in milliseconds(SoundJS parameter). Default is 0.

  • loop Int

    How many times the sound should loop. Use -1 (or true) for infinite loops (SoundJS parameter). Default is no looping.

  • volume Number

    The volume to play the sound at (0 to 1). Omit to use the default for the sound.

  • pan Number

    The panning to start the sound at (-1 to 1). Default is centered (0).

Returns:

SoundInst:

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
)
public

Defined in preload:860

Preloads a list of sounds.

Parameters:

  • list Array

    An array of sound aliases to load.

  • callback Function

    The function to call when all sounds have been loaded.

preloadSound

(
  • alias
  • callback
)
public

Defined in preloadSound:833

Preloads a specific sound.

Parameters:

  • alias String

    The alias of the sound to load.

  • callback Function

    The function to call when the sound is finished loading.

setContextMute

(
  • context
  • muted
)
public

Defined in setContextMute:773

Sets mute status of all sounds in a context

Parameters:

  • context String

    The name of the context to modify.

  • muted Bool

    If the context should be muted.

setContextVolume

(
  • context
  • volume
)
public

Sets volume of a context. Individual sound volumes are multiplied by this value.

Parameters:

  • context String

    The name of the context to modify.

  • volume Number

    The volume for the context (0 to 1).

stop

(
  • alias
)
public

Defined in stop:629

Stops all playing or loading instances of a given sound.

Parameters:

  • alias String

    The alias of the sound to stop.

stopContext

(
  • context
)
public

Defined in stopContext:685

Stops all sounds in a given context.

Parameters:

  • context String

    The name of the context to stop.

unload

(
  • list
)
public

Defined in unload:949

Unloads a list of sounds to reclaim memory if possible. If the sounds are playing, they are stopped.

Parameters:

  • list Array

    An array of sound aliases to unload.

unpauseAll

() public

Defined in unpauseAll:761

Unpauses all sounds.

unpauseSound

(
  • alias
)
public

Defined in unpauseSound:727

Unpauses a specific sound.

Parameters:

  • alias String

    The alias of the sound to pause. Internally, this can also be the object from the _sounds dictionary directly.

Properties

_contexts

Object private

Defined in _contexts:68

Dictionary of SoundContexts.

_playAfterLoadBound

Function private

A copy of _playAfterLoad bound to this Sound instance.

_pool

Array private

Defined in _pool:54

Array of SoundInst objects waiting to be used.

_sounds

Object private

Defined in _sounds:40

Dictionary of sound objects, containing configuration info and playback objects.

instance

Sound public static

Defined in instance:167

The singleton instance of Sound.

supportedSound

String public

Defined in supportedSound:61

The extension of the supported sound type that will be used.

UNHANDLED

String public static

Defined in UNHANDLED:82

A constant for telling Sound not to handle a sound with play(), but to return what SoundJS returns directly.