Class: NoAudioSoundManager

Phaser.Sound. NoAudioSoundManager

No-audio implementation of the Sound Manager. It is used if audio has been disabled in the game config or the device doesn't support any audio.

It represents a graceful degradation of Sound Manager logic that provides minimal functionality and prevents Phaser projects that use audio from breaking on devices that don't support any audio playback technologies.


new NoAudioSoundManager(game)

Parameters:
Name Type Description
game Phaser.Game

Reference to the current game instance.

Since: 3.0.0
Source: src/sound/noaudio/NoAudioSoundManager.js (Line 14)

Extends

Members


detune :number

Global detuning of all sounds in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 0
Source: src/sound/BaseSoundManager.js (Line 676)

<readonly> game :Phaser.Game

Local reference to game.

Type:
Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 43)

<readonly> jsonCache :Phaser.Cache.BaseCache

Local reference to the JSON Cache, as used by Audio Sprites.

Type:
Since: 3.7.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 53)

<readonly> locked :boolean

Mobile devices require sounds to be triggered from an explicit user action, such as a tap, before any sound can be loaded/played on a web page. Set to true if the audio system is currently locked awaiting user interaction.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 127)

mute :boolean

Global mute setting.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • false
Source: src/sound/BaseSoundManager.js (Line 74)

pauseOnBlur :boolean

Flag indicating if sounds should be paused when game looses focus, for instance when user switches to another tab/program/app.

Type:
  • boolean
Since: 3.0.0
Inherited From:
Default Value:
  • true
Source: src/sound/BaseSoundManager.js (Line 94)

rate :number

Global playback rate at which all the sounds will be played. Value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audio's playback speed.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 1
Source: src/sound/BaseSoundManager.js (Line 626)

volume :number

Global volume setting.

Type:
  • number
Since: 3.0.0
Inherited From:
Default Value:
  • 1
Source: src/sound/BaseSoundManager.js (Line 84)

Methods


add(key [, config])

Adds a new sound into the sound manager.

Parameters:
Name Type Argument Description
key string

Asset key for the sound.

config Phaser.Types.Sound.SoundConfig <optional>

An optional config object containing default sound settings.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 157)
Returns:

The new sound instance.

Type
Phaser.Sound.BaseSound

addAudioSprite(key [, config])

Adds a new audio sprite sound into the sound manager. Audio Sprites are a combination of audio files and a JSON configuration. The JSON follows the format of that created by https://github.com/tonistiigi/audiosprite

Parameters:
Name Type Argument Description
key string

Asset key for the sound.

config Phaser.Types.Sound.SoundConfig <optional>

An optional config object containing default sound settings.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 171)
Returns:

The new audio sprite sound instance.

Type
Phaser.Sound.HTML5AudioSound | Phaser.Sound.WebAudioSound

addListener(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 111)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

destroy()

Destroys all the sounds in the game and all associated events.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 560)

emit(event [, args])

Calls each of the listeners registered for a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

args * <optional>
<repeatable>

Additional arguments that will be passed to the event handler.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 86)
Returns:

true if the event had listeners, else false.

Type
boolean

eventNames()

Return an array listing the events for which the emitter has registered listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 55)
Returns:
Type
Array.<(string|symbol)>

get(key)

Gets the first sound in the manager matching the given key, if any.

Parameters:
Name Type Description
key string

Sound asset key.

Since: 3.23.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 216)
Returns:
  • The sound, or null.
Type
Phaser.Sound.BaseSound

getAll(key)

Gets any sounds in the manager matching the given key.

Parameters:
Name Type Description
key string

Sound asset key.

Since: 3.23.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 231)
Returns:
  • The sounds, or an empty array.
Type
Array.<Phaser.Sound.BaseSound>

listenerCount(event)

Return the number of listeners listening to a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 75)
Returns:

The number of listeners.

Type
number

listeners(event)

Return the listeners registered for a given event.

Parameters:
Name Type Description
event string | symbol

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 64)
Returns:

The registered listeners.

Type
Array.<function()>

off(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 151)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

on(event, fn [, context])

Add a listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 98)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

<protected> onBlur()

Method used internally for pausing sound manager if Phaser.Sound.BaseSoundManager#pauseOnBlur is set to true.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 472)

once(event, fn [, context])

Add a one-time listener for a given event.

Parameters:
Name Type Argument Default Description
event string | symbol

The event name.

fn function

The listener function.

context * <optional>
this

The context to invoke the listener with.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 124)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

<protected> onFocus()

Method used internally for resuming sound manager if Phaser.Sound.BaseSoundManager#pauseOnBlur is set to true.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 483)

pauseAll()

Pauses all the sounds in the game.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 385)
Fires:

play(key [, extra])

Adds a new sound to the sound manager and plays it. The sound will be automatically removed (destroyed) once playback ends. This lets you play a new sound on the fly without the need to keep a reference to it.

Parameters:
Name Type Argument Description
key string

Asset key for the sound.

extra Phaser.Types.Sound.SoundConfig | Phaser.Types.Sound.SoundMarker <optional>

An optional additional object containing settings to be applied to the sound. It could be either config or marker object.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 246)
Listens to Events:
Returns:

Whether the sound started playing successfully.

Type
boolean

playAudioSprite(key, spriteName [, config])

Adds a new audio sprite sound to the sound manager and plays it. The sprite will be automatically removed (destroyed) once playback ends. This lets you play a new sound on the fly without the need to keep a reference to it.

Parameters:
Name Type Argument Description
key string

Asset key for the sound.

spriteName string

The name of the sound sprite to play.

config Phaser.Types.Sound.SoundConfig <optional>

An optional config object containing default sound settings.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 285)
Listens to Events:
Returns:

Whether the audio sprite sound started playing successfully.

Type
boolean

remove(sound)

Removes a sound from the sound manager. The removed sound is destroyed before removal.

Parameters:
Name Type Description
sound Phaser.Sound.BaseSound

The sound object to remove.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 309)
Returns:

True if the sound was removed successfully, otherwise false.

Type
boolean

removeAll()

Removes all sounds from the manager, destroying the sounds.

Since: 3.23.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 337)

removeAllListeners( [event])

Remove all listeners, or those of the specified event.

Parameters:
Name Type Argument Description
event string | symbol <optional>

The event name.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 165)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

removeByKey(key)

Removes all sounds from the sound manager 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.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 353)
Returns:

The number of matching sound objects that were removed.

Type
number

removeListener(event [, fn] [, context] [, once])

Remove the listeners of a given event.

Parameters:
Name Type Argument Description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 137)
Returns:

this.

Type
Phaser.Sound.NoAudioSoundManager

resumeAll()

Resumes all the sounds in the game.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 402)
Fires:

setDetune(value)

Sets the global detuning of all sounds in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

Parameters:
Name Type Description
value number

The range of the value is -1200 to 1200, but we recommend setting it to 50.

Since: 3.3.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 657)
Fires:
Returns:

This Sound Manager.

Type
Phaser.Sound.BaseSoundManager

setRate(value)

Sets the global playback rate at which all the sounds will be played.

For example, a value of 1.0 plays the audio at full speed, 0.5 plays the audio at half speed and 2.0 doubles the audios playback speed.

Parameters:
Name Type Description
value number

Global playback rate at which all the sounds will be played.

Since: 3.3.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 605)
Fires:
Returns:

This Sound Manager.

Type
Phaser.Sound.BaseSoundManager

shutdown()

Removes all listeners.

Since: 3.0.0
Inherited From:
Source: src/events/EventEmitter.js (Line 31)

stopAll()

Stops all the sounds in the game.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 419)
Fires:

stopByKey(key)

Stops any sounds matching the given key.

Parameters:
Name Type Description
key string

Sound asset key.

Since: 3.23.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 437)
Returns:
  • How many sounds were stopped.
Type
number

<protected> unlock()

Method used internally for unlocking audio playback on devices that require user interaction before any sound can be played on a web page.

Read more about how this issue is handled here in this article.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 459)

<protected> update(time, delta)

Update method called on every game step. Removes destroyed sounds and updates every active sound in the game.

Parameters:
Name Type Description
time number

The current timestamp as generated by the Request Animation Frame or SetTimeout.

delta number

The delta time elapsed since the last frame.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSoundManager.js (Line 524)
Fires: