Class CAAT.Module.Audio.AudioManager
Defined in: AudioManager.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Field Attributes | Field Name and Description |
---|---|
A collection of Audio objects.
|
|
available formats for audio elements.
|
|
Audio formats.
|
|
A cache of empty Audio objects.
|
|
Are FX sounds enabled ?
|
|
Currently looping Audio objects.
|
|
The only background music audio channel.
|
|
Is music enabled ?
|
|
Currently used Audio objects.
|
Method Attributes | Method Name and Description |
---|---|
<private> |
__getAudioUrl(url)
|
<private> |
__init()
|
<private> | |
addAudio(id, array_of_url_or_domnodes, endplaying_callback)
creates an Audio object and adds it to the audio cache.
|
|
<private> |
addAudioElement(id, element, endplaying_callback)
Adds an elements to the audio cache.
|
<private> |
addAudioFromDomNode(id, audio, endplaying_callback)
Tries to add an audio tag to the available list of valid audios.
|
<private> |
addAudioFromURL(id, url, endplaying_callback)
Tries to add an audio tag to the available list of valid audios.
|
cancelPlay(id)
cancel all instances of a sound identified by id.
|
|
cancelPlayByChannel(audioObject)
cancel a channel sound
|
|
endSound()
Cancel all playing audio channels
Get back the playing channels to available channel list.
|
|
getAudio(aId)
Returns an audio object.
|
|
initialize(numChannels)
Initializes the sound subsystem by creating a fixed number of Audio channels.
|
|
loop(id)
This method creates a new AudioChannel to loop the sound with.
|
|
play(id)
Plays an audio file from the cache if any sound channel is available.
|
|
playMusic(id)
|
|
setAudioFormatExtensions(formats)
|
|
setMusicEnabled(enable)
|
|
setSoundEffectsEnabled(enable)
|
|
setVolume(id, volume)
Set an audio object volume.
|
|
- Parameters:
- url
The audio element can be one of the two forms:
- Either an HTMLAudioElement/Audio object or a string url.
- An array of elements of the previous form.
When the audio attribute is an array, this function will iterate throught the array elements until a suitable audio element to be played is found. When this is the case, the other array elements won't be taken into account. The valid form of using this addAudio method will be:
1.
addAudio( id, url } ). In this case, if the resource pointed by url is
not suitable to be played (i.e. a call to the Audio element's canPlayType method return 'no')
no resource will be added under such id, so no sound will be played when invoking the play(id)
method.
2.
addAudio( id, dom_audio_tag ). In this case, the same logic than previous case is applied, but
this time, the parameter url is expected to be an audio tag present in the html file.
3.
addAudio( id, [array_of_url_or_domaudiotag] ). In this case, the function tries to locate a valid
resource to be played in any of the elements contained in the array. The array element's can
be any type of case 1 and 2. As soon as a valid resource is found, it will be associated to the
id in the valid audio resources to be played list.
- Parameters:
- id
- array_of_url_or_domnodes
- endplaying_callback
- Returns:
- this
- Parameters:
- id
- {object} an object to associate the audio element (if suitable to be played).
- element
- {URL|HTMLElement} an url or html audio tag.
- endplaying_callback
- {function} callback to be called upon sound end.
- Returns:
- {boolean} a boolean indicating whether the browser can play this resource.
- Parameters:
- id
- {object} an object to associate the audio element (if suitable to be played).
- audio
- {HTMLAudioElement} a DOM audio node.
- endplaying_callback
- {function} callback to be called upon sound end.
- Returns:
- {boolean} a boolean indicating whether the browser can play this resource.
- Parameters:
- id
- {object} an object to associate the audio element (if suitable to be played).
- url
- {string} a string describing an url.
- endplaying_callback
- {function} callback to be called upon sound end.
- Returns:
- {boolean} a boolean indicating whether the browser can play this resource.
- Parameters:
- id
- Returns:
- {*}
- Parameters:
- audioObject
- Returns:
- {*}
- Returns:
- this
- Parameters:
- aId
- {object} the id associated to the target Audio object.
- Returns:
- {object} the HTMLAudioElement addociated to the given id.
- Parameters:
- numChannels
- {number} number of channels to pre-create. 8 by default.
- Returns:
- this.
pause()
method to stop playing a loop.
Firefox does not honor the loop property, so looping is performed by attending end playing event on audio elements.
- Parameters:
- id
- Returns:
- {HTMLElement} an Audio instance if a valid sound id is supplied. Null otherwise
- Parameters:
- id
- {object} an object identifying a sound in the sound cache.
- Returns:
- {id: {Object}|audio: {(Audio|HTMLAudioElement)}}
- Parameters:
- id
- Parameters:
- formats
- Parameters:
- enable
- Parameters:
- enable
- Parameters:
- id
- {object} an audio Id
- volume
- {number} volume to set. The volume value is not checked.
- Returns:
- this