new SoundManager(game)
The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it. Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files. The audio file type and the encoding of those files are extremely important. Not all browsers can play all audio formats. There is a good guide to what's supported here: http://hpr.dogphilosophy.net/test/
Parameters:
Name | Type | Description |
---|---|---|
game |
Phaser.Game | reference to the current game instance. |
- Source - sound/SoundManager.js, line 17
Members
-
channels :number
-
The number of audio channels to use in playback.
- Default Value:
- 32
- Source - sound/SoundManager.js, line 103
-
connectToMaster :boolean
-
Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node.
- Default Value:
- true
- Source - sound/SoundManager.js, line 91
-
context :AudioContext
-
The AudioContext being used for playback.
- Default Value:
- null
- Source - sound/SoundManager.js, line 67
-
game :Phaser.Game
-
Local reference to game.
- Source - sound/SoundManager.js, line 22
-
mute :boolean
-
Gets or sets the muted state of the SoundManager. This effects all sounds in the game.
- Source - sound/SoundManager.js, line 544
-
noAudio :boolean
-
Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead.
- Default Value:
- false
- Source - sound/SoundManager.js, line 85
-
onSoundDecode :Phaser.Signal
-
The event dispatched when a sound decodes (typically only for mp3 files)
- Source - sound/SoundManager.js, line 27
-
touchLocked :boolean
-
true if the audio system is currently locked awaiting a touch event.
- Default Value:
- false
- Source - sound/SoundManager.js, line 97
-
<readonly> usingAudioTag :boolean
-
true if the sound is being played via the Audio tag.
- Source - sound/SoundManager.js, line 79
-
<readonly> usingWebAudio :boolean
-
true if this sound is being played with Web Audio.
- Source - sound/SoundManager.js, line 73
-
volume :number
-
Gets or sets the global volume of the SoundManager, a value between 0 and 1.
- Source - sound/SoundManager.js, line 584
Methods
-
add(key, volume, loop, connect) → {Phaser.Sound}
-
Adds a new Sound into the SoundManager.
Parameters:
Name Type Argument Default Description key
string Asset key for the sound.
volume
number <optional>
1 Default value for the volume.
loop
boolean <optional>
false Whether or not the sound will loop.
connect
boolean <optional>
true Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.
Returns:
The new sound instance.
- Source - sound/SoundManager.js, line 345
-
addSprite(key) → {Phaser.AudioSprite}
-
Adds a new AudioSprite into the SoundManager.
Parameters:
Name Type Description key
string Asset key for the sound.
Returns:
The new AudioSprite instance.
- Source - sound/SoundManager.js, line 369
-
<internal> boot()
-
Initialises the sound manager.
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source - sound/SoundManager.js, line 109
-
decode(key, sound)
-
Decode a sound by its assets key.
Parameters:
Name Type Argument Description key
string Assets key of the sound to be decoded.
sound
Phaser.Sound <optional>
Its buffer will be set to decoded data.
- Source - sound/SoundManager.js, line 284
-
destroy()
-
Stops all the sounds in the game, then destroys them and finally clears up any callbacks.
- Source - sound/SoundManager.js, line 518
-
pauseAll()
-
Pauses all the sounds in the game.
- Source - sound/SoundManager.js, line 250
-
play(key, volume, loop) → {Phaser.Sound}
-
Adds a new Sound into the SoundManager and starts it playing.
Parameters:
Name Type Argument Default Description key
string Asset key for the sound.
volume
number <optional>
1 Default value for the volume.
loop
boolean <optional>
false Whether or not the sound will loop.
Returns:
The new sound instance.
- Source - sound/SoundManager.js, line 436
-
remove(sound) → {boolean}
-
Removes a Sound from the SoundManager. The removed Sound is destroyed before removal.
Parameters:
Name Type Description sound
Phaser.Sound The sound object to remove.
Returns:
boolean -True if the sound was removed successfully, otherwise false.
- Source - sound/SoundManager.js, line 384
-
removeByKey(key) → {number}
-
Removes all Sounds from the SoundManager that have an asset key matching the given value. The removed Sounds are destroyed before removal.
Parameters:
Name Type Description key
string The key to match when removing sound objects.
Returns:
number -The number of matching sound objects that were removed.
- Source - sound/SoundManager.js, line 409
-
resumeAll()
-
Resumes every sound in the game.
- Source - sound/SoundManager.js, line 267
-
stopAll()
-
Stops all the sounds in the game.
- Source - sound/SoundManager.js, line 233
-
unlock()
-
Enables the audio, usually after the first touch.
- Source - sound/SoundManager.js, line 199
-
update()
-
Updates every sound in the game.
- Source - sound/SoundManager.js, line 317