Class Index | File Index

Classes


Class CAAT.Module.Audio.AudioManager


Defined in: AudioManager.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
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 Summary
Method Attributes Method Name and Description
<private>  
<private>  
<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.
 
cancel all instances of a sound identified by id.
 
cancelPlayByChannel(audioObject)
cancel a channel sound
 
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.
 
 
 
 
 
setVolume(id, volume)
Set an audio object volume.
 
Class Detail
CAAT.Module.Audio.AudioManager()
Field Detail
audioCache
A collection of Audio objects.

audioFormatExtensions
available formats for audio elements. the system will load audio files with the extensions in this preferred order.

audioTypes
Audio formats.

channels
A cache of empty Audio objects.

fxEnabled
Are FX sounds enabled ?

loopingChannels
Currently looping Audio objects.

musicChannel
The only background music audio channel.

musicEnabled
Is music enabled ?

workingChannels
Currently used Audio objects.
Method Detail
<private> __getAudioUrl(url)
Parameters:
url

<private> __init()

<private> __setCurrentAudioFormatExtension()

addAudio(id, array_of_url_or_domnodes, endplaying_callback)
creates an Audio object and adds it to the audio cache. This function expects audio data described by two elements, an id and an object which will describe an audio element to be associated with the id. The object will be of the form array, dom node or a url string.

The audio element can be one of the two forms:

  1. Either an HTMLAudioElement/Audio object or a string url.
  2. 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

<private> {boolean} addAudioElement(id, element, endplaying_callback)
Adds an elements to the audio cache.
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.

<private> {boolean} addAudioFromDomNode(id, audio, endplaying_callback)
Tries to add an audio tag to the available list of valid audios. The audio element comes from an HTMLAudioElement.
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.

<private> {boolean} addAudioFromURL(id, url, endplaying_callback)
Tries to add an audio tag to the available list of valid audios. The audio is described by a url.
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.

{*} cancelPlay(id)
cancel all instances of a sound identified by id. This id is the value set to identify a sound.
Parameters:
id
Returns:
{*}

{*} cancelPlayByChannel(audioObject)
cancel a channel sound
Parameters:
audioObject
Returns:
{*}

endSound()
Cancel all playing audio channels Get back the playing channels to available channel list.
Returns:
this

{object} getAudio(aId)
Returns an audio object.
Parameters:
aId
{object} the id associated to the target Audio object.
Returns:
{object} the HTMLAudioElement addociated to the given id.

initialize(numChannels)
Initializes the sound subsystem by creating a fixed number of Audio channels. Every channel registers a handler for sound playing finalization. If a callback is set, the callback function will be called with the associated sound id in the cache.
Parameters:
numChannels
{number} number of channels to pre-create. 8 by default.
Returns:
this.

isMusicEnabled()

isSoundEffectsEnabled()

{HTMLElement} loop(id)
This method creates a new AudioChannel to loop the sound with. It returns an Audio object so that the developer can cancel the sound loop at will. The user must call 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

{id: {Object}|audio: {(Audio|HTMLAudioElement)}} play(id)
Plays an audio file from the cache if any sound channel is available. The playing sound will occupy a sound channel and when ends playing will leave the channel free for any other sound to be played in.
Parameters:
id
{object} an object identifying a sound in the sound cache.
Returns:
{id: {Object}|audio: {(Audio|HTMLAudioElement)}}

playMusic(id)
Parameters:
id

setAudioFormatExtensions(formats)
Parameters:
formats

setMusicEnabled(enable)
Parameters:
enable

setSoundEffectsEnabled(enable)
Parameters:
enable

setVolume(id, volume)
Set an audio object volume.
Parameters:
id
{object} an audio Id
volume
{number} volume to set. The volume value is not checked.
Returns:
this

stopMusic()

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Jul 01 2013 04:59:19 GMT-0700 (PDT)