AudioManager Class
Grapefruit Audio API, provides an easy interface to use WebAudoiAPI with a fallback to HTML5 Audio
The GF Audio API was originally based on Howler.js
Generally you will use this via the game.audio
or state.audio
properties.
Constructor
AudioManager
-
game
-
parent
Parameters:
-
game
GameThe game instance this manager belongs to
-
parent
AudioManagerThe parent audio manager this manager belongs to. This is used to create a web audio API node heirarchy.
Item Index
Methods
add
-
key
-
[settings]
Creates a new audio player for a peice of audio
Parameters:
-
key
StringThe unique cache key for the preloaded audio
-
[settings]
Object optionalAll the settings for the audio player
-
[volume]
Number optionalThe volume of this audio clip
-
[autoplay]
Boolean optionalAutomatically start playing after loaded
-
[loop]
Boolean optionalReplay the audio when it finishes
-
[sprite]
Object optionalA map of string names -> [start, duration] arrays. You can use it to put multiple sounds in one file
-
[pos3d]
Arrayoptional 3D coords of where the audio should sound as if it came from (only works with WebAudio)
-
[buffer]
Boolean optionalWebAudio will load the entire file before playing, making this true forces HTML5Audio which will buffer and play
-
[format]
String optionalForce an extension override
-
Returns:
Will return the new audio player, or false if we couldn't determine a compatible url
attach
-
sound
Attaches an AudioPlayer to this manager, if using webAudio this means that the sound will connect to this masterGain node and inherit anything that happens to it (such as muting).
Parameters:
-
sound
AudioPlayerThe player to attach to this manager
Returns:
The newly attached audio player
detach
-
sound
Detaches an AudioPlayer from this manager, if using webAudio this means that the sound will disconnect from this masterGain node and stop inheriting anything that happens to it (such as muting).
Parameters:
-
sound
AudioPlayerThe player to detach from this manager
Returns:
The detached audio player
getVolume
()
Returns the current master volume
remove
-
key
Removes an audio player from the manager
Parameters:
-
key
StringThe unique cache key for the preloaded audio
Returns:
Will return the audio player removed, or false if none was removed
setMuted
()
AudioManager
chainable
Sets whether or not this manager is muted
Returns:
Returns itself.
setParent
-
parent
Sets the parent of this audio manager, if using webAudio this means that we connect to the parent masterGain node and inherit anything that happens to it (such as muting).
Parameters:
-
parent
AudioManagerThe parent to connect to, or
null
to connect to the global context
Returns:
Returns itself.
setVolume
-
value
Sets the current master volume
Parameters:
-
value
Number
Properties
_volume
Number
private
The master volume of the player
Default: 1
canPlay
Boolean
If we have some way of playing audio
ctx
AudioContext
The Web Audio API context if we are using it
muted
Boolean
private
Whether the player is muted or not
Default: false
volume
Number
The master volume of all the audio playing
Default: 1