new SoundManager(game)
Sound Manager constructor. 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:
Members
-
channels
-
- Default Value:
- 32
- Source:
Properties:
Name Type Description channelsnumber The number of audio channels to use in playback.
-
connectToMaster
-
- Default Value:
- true
- Source:
Properties:
Name Type Description connectToMasterboolean Used in conjunction with Sound.externalNode this allows you to stop a Sound node being connected to the SoundManager master gain node.
-
context
-
- Default Value:
- null
- Source:
Properties:
Name Type Description contextAudioContext The AudioContext being used for playback.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game Local reference to game.
-
mute
-
- Source:
Properties:
Name Type Description muteboolean Gets or sets the muted state of the SoundManager. This effects all sounds in the game.
-
noAudio
-
- Default Value:
- false
- Source:
Properties:
Name Type Description noAudioboolean Has audio been disabled via the PhaserGlobal object? Useful if you need to use a 3rd party audio library instead.
-
onSoundDecode
-
- Source:
Properties:
Name Type Description onSoundDecodePhaser.Signal The event dispatched when a sound decodes (typically only for mp3 files)
-
touchLocked
-
- Default Value:
- false
- Source:
Properties:
Name Type Description touchLockedboolean true if the audio system is currently locked awaiting a touch event.
-
<readonly> usingAudioTag
-
- Source:
Properties:
Name Type Description usingAudioTagboolean true if the sound is being played via the Audio tag.
-
<readonly> usingWebAudio
-
- Source:
Properties:
Name Type Description usingWebAudioboolean true if this sound is being played with Web Audio.
-
volume
-
- Source:
Properties:
Name Type Description volumenumber Gets or sets the global volume of the SoundManager, a value between 0 and 1.
Methods
-
add(key, volume, loop, connect) → {Phaser.Sound}
-
Adds a new Sound into the SoundManager.
Parameters:
Name Type Argument Default Description keystring Asset key for the sound.
volumenumber <optional>
1 Default value for the volume.
loopboolean <optional>
false Whether or not the sound will loop.
connectboolean <optional>
true Controls if the created Sound object will connect to the master gainNode of the SoundManager when running under WebAudio.
- Source:
Returns:
The new sound instance.
- Type
- Phaser.Sound
-
<protected> boot()
-
Initialises the sound manager.
- Source:
-
decode(key, sound)
-
Decode a sound by its assets key.
Parameters:
Name Type Argument Description keystring Assets key of the sound to be decoded.
soundPhaser.Sound <optional>
Its buffer will be set to decoded data.
- Source:
-
destroy()
-
Stops all the sounds in the game, then destroys them and finally clears up any callbacks.
- Source:
-
pauseAll()
-
Pauses all the sounds in the game.
- Source:
-
play(key, volume, loop) → {Phaser.Sound}
-
Adds a new Sound into the SoundManager and starts it playing.
Parameters:
Name Type Argument Default Description keystring Asset key for the sound.
volumenumber <optional>
1 Default value for the volume.
loopboolean <optional>
false Whether or not the sound will loop.
- Source:
Returns:
The new sound instance.
- Type
- Phaser.Sound
-
remove(sound) → {boolean}
-
Removes a Sound from the SoundManager. The removed Sound is destroyed before removal.
Parameters:
Name Type Description soundPhaser.Sound The sound object to remove.
- Source:
Returns:
True if the sound was removed successfully, otherwise false.
- Type
- boolean
-
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 keystring The key to match when removing sound objects.
- Source:
Returns:
The number of matching sound objects that were removed.
- Type
- number
-
resumeAll()
-
Resumes every sound in the game.
- Source:
-
stopAll()
-
Stops all the sounds in the game.
- Source:
-
unlock()
-
Enables the audio, usually after the first touch.
- Source:
-
update()
-
Updates every sound in the game.
- Source: