SoundJS

SoundJS  0.1

SoundJS > SoundJS > SoundJS
Search:
 
Filters

static Class SoundJS

Properties

AUDIO_TIMEOUT - static Number

The duration in milliseconds to wait before declaring a timeout when loading a sound.
Default Value: 8000

INTERRUPT_ANY - static Number

The interrupt mode to use when all instances are in use. Interrupt the the first instance.
Default Value: 1

INTERRUPT_EARLY - static Number

The interrupt mode to use when all instances are in use. Interrupt the sound that is at the earliest position.
Default Value: 2

INTERRUPT_LATE - static Number

The interrupt mode to use when all instances are in use. Interrupt the sound that is at the latest position.
Default Value: 3

INTERRUPT_NONE - static Number

The interrupt mode to use when all instances are in use. Do not interrupt any sounds.
Default Value: 4

loadQueue - protected Array

An array containing all of the sounds waiting to be loaded.

onLoadQueueComplete - static Function

The function to call when all sounds in the preload queue have finished loading.

onProgress - static Function

The function to call whenever progress changes.

onSoundComplete - static Function

The function to call when a sound finishes playing.

onSoundLoadComplete - static Function

The function to call when a sound has finished loading.

onSoundLoadError - static Function

The function to call when an error occurs loading a sound file.

onSoundTimeout - static Function

The function to call when a loading sound times out. The timeout duration is determined by the AUDIO_TIMEOUT parameter.

soundHash - protected Array

An array containing all of the sound objects created by this manager.

Methods

add

void add ( name , src , instances )
Manage, load, and perform DOM injection of a sound. If the load queue is empty, it will trigger an immediate load, otherwise it will be added to the end of the loading queue and loaded in sequence. If instances of a sound by that name already exist, the number of instances is increased and the element 'src' is ignored.
Parameters:
name <String> : The reference to this sound effect
src <String> : The filepath to load from
instances <Number> : The number of simultaneous versions of this sound you wish to play (max sounds limited by Browser and Computer).
Returns: void

addBatch

static void addBatch ( params )
Manage, load, and perform DOM injections of a sound, or set of sounds. This method is identical to the SoundJS.add() method, except: 1) An array of objects representing the parameters for each add call is required. [{name:'soundName', src:'sound.mp3', instances:1}, {name:'soundName', src:'sound.ogg', instances:4}] 2) It waits until all items are added to the queue before beginning the load operation, which can even out erroneous finished loading calls in high speed environments such as local environments or with cached sounds.
Parameters:
params <Array> : Array of 'name:, src:, instances:' objects.
Returns: void

getCurrentLoadProgress

static Number getCurrentLoadProgress ( )
Get the current load progress for the sound queue.
Returns: Number
A number 0-1 indicating percentage loaded of the current loading queue.

getInstance

static Sound object getInstance ( name , instance )
Get a reference to the DOM sound object by name and instance.
Parameters:
name <String> : The sound name to find the instance in.
instance <String> : The specific instance to grab.
Returns: Sound object
The Sound Element specified by name and instance or null.

getMasterVolume

static void getMasterVolume ( )
Get the current master volume level
Returns: void

getMaxInstances

static Number getMaxInstances ( )
Get the maximum number of instances the browser can run.
Returns: Number
Assumption of maximum instances the browser can run, the actual number varies from browser to browser and machine to machine, and is largely based on the sound card.

getNumInstances

static Number getNumInstances ( name )
List the number of instances used by a specific sound. If the value of the name is null, check the entire system
Parameters:
name <String> = null: (optional) Name of the sound to lookup.
Returns: Number
The number of instances currently instantiated or -1 if an invalid name is passed in.

getVolume

static Number getVolume ( name , instance )
Get the volume of a sound instance. If no instance is provided the volume of the first instance will be returned.
Parameters:
name <String> = null: (optional) If null the function adjusts all sounds.
instance <Number> = null: (optional) If null the function gets the first instance.
Returns: Number
the volume of the specified instance or -1 if the instance does not exist.

isLoaded

static Boolean isLoaded ( name )
Check to see if specified sound is loaded/valid. If the value of the name is null, check all sounds are loaded.
Parameters:
name <String> = null: (optional) The sound to check.
Returns: Boolean
Indicating if the specified sound is valid & loaded

pause

static Boolean pause ( name , instance )
Pause specified instance(s) of this sound.
Parameters:
name <String> = null: (optional) If null the function adjusts all sounds.
instance <Number> = null: (optional) If null the function adjusts all instances.
Returns: Boolean
Success of operation.

play

static Number play ( name , interrupt , volume , loop , delay )
Play the a sound file with the defined properties. The function returns one of three things; 1) The instance number played if sound was played successfully 2) 'NaN' if an erroneous parameter is passed, or the interrupt method forbids playing the sound 3) -1 on a delayed call, as the instance being played cannot be determined till the delay is over If the instance is needed on a delayed call, the best practice is to delay the call like so: e.g. setTimeout(function(){ myVar = SoundJS.play("sound")}, 3000); Note: this closure is needed for full functionality cross browsers.
Parameters:
name <String> : Specifies the url to the sound file to play (as defined in the add functions).
interrupt <Number> = SoundJS.INTERRUPT_NONE: (optional) Defines the interrupt behavior if all instances are currently used.
volume <Number> = 1: (optional) Specifies to volume at which to play that sound instance.
loop <Boolean> = false: (optional) Sets the loop parameter on the sound instance.
delay <Number> = 0: (optional) Specifies how long to wait before looking for a sound instance to play the sound.
Returns: Number
The index of the sound played, NaN, or -1.

remove

static Boolean remove ( name , count )
Remove the specified number of sound instances from the DOM. WARNING: remove ignores interrupt modes and current actions, and will remove the last instances regardless of their status.
Parameters:
name <String> = null: (optional) Note that the function removes all sounds if it is null.
count <Number> = null: (optional) Note that the function removes all instances if it is null.
Returns: Boolean
Success of operation.

resume

static Boolean resume ( name , instance )
Resume specified instance(s) of this sound.
Parameters:
name <String> = null: (optional) If null the function adjusts all sounds.
instance <String> = null: (optional) If null the function adjusts all instances.
Returns: Boolean
Success of operation.

setMasterVolume

static void setMasterVolume ( value )
Change the master volume level
Parameters:
value <Number> = null: (optional) New master volume.
Returns: void

setMute

static Boolean setMute ( isMuted , name , instance )
Specify the mute value of specified instance(s) of this sound.
Parameters:
isMuted <String> : Whether or not the target is muted.
name <String> = null: (optional) Note: The function adjusts all sounds if the value is null.
instance <Array> = null: (optional) Note: The function adjusts all instances if the value is null.
Returns: Boolean
Success of operation.

setVolume

static Boolean setVolume ( value , name , instance )
Adjust the volume of specified instance(s) of this sound.
Parameters:
value <String> : The volume to set the target to.
name <String> = null: (optional) If null the function adjusts all sounds.
instance <Number> = null: (optional) If null the function adjusts all instances.
Returns: Boolean
Success of operation.

stop

static Boolean stop ( name , instance )
Stop specified instance(s) of this sound.
Parameters:
name <String> = null: (optional) If null the function adjusts all sounds.
instance <String> = null: (optional) If null the function adjusts all instances.
Returns: Boolean
Success of operation.