Class: HTML5AudioSound

Phaser.Sound. HTML5AudioSound

HTML5 Audio implementation of the sound.


new HTML5AudioSound(manager, key [, config])

Parameters:
Name Type Argument Default Description
manager Phaser.Sound.HTML5AudioSoundManager

Reference to the current sound manager instance.

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
Source: src/sound/html5/HTML5AudioSound.js (Line 13)

Extends

Members


<readonly> currentMarker :Phaser.Types.Sound.SoundMarker

Currently playing marker. 'null' if whole sound is playing.

Type:
Since: 3.0.0
Inherited From:
Default Value:
  • null
Source: src/sound/BaseSound.js (Line 160)

detune :number

The detune value of this Sound, given in cents. The range of the value is -1200 to 1200, but we recommend setting it to 50.

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/sound/html5/HTML5AudioSound.js (Line 735)

<readonly> duration :number

A value representing the duration, in seconds. It could be total sound duration or a marker duration.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 93)

<readonly> isPaused :boolean

Flag indicating if sound is currently paused.

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

<readonly> isPlaying :boolean

Flag indicating if sound is currently playing.

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

<readonly> key :string

Asset key for the sound.

Type:
  • string
Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 48)

loop :boolean

Flag indicating whether or not the sound or current sound marker will loop.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/sound/html5/HTML5AudioSound.js (Line 867)

<readonly> markers :Object.<string, Phaser.Types.Sound.SoundMarker>

Object containing markers definitions.

Type:
Since: 3.0.0
Inherited From:
Default Value:
  • {}
Source: src/sound/BaseSound.js (Line 149)

mute :boolean

Boolean indicating whether the sound is muted or not. Gets or sets the muted state of this sound.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/sound/html5/HTML5AudioSound.js (Line 579)

pan :number

Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).

Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event.

Type:
  • number
Since: 3.50.0
Default Value:
  • 0
Source: src/sound/html5/HTML5AudioSound.js (Line 920)

rate :number

Rate at which this Sound 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 audios playback speed.

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/sound/html5/HTML5AudioSound.js (Line 678)

seek :number

Property representing the position of playback for this sound, in seconds. Setting it to a specific value moves current playback to that position. The value given is clamped to the range 0 to current marker duration. Setting seek of a stopped sound has no effect.

Type:
  • number
Since: 3.0.0
Source: src/sound/html5/HTML5AudioSound.js (Line 789)

<readonly> totalDuration :number

The total duration of the sound in seconds.

Type:
  • number
Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 104)

<readonly> totalRate :number

A property that holds the value of sound's actual playback rate, after its rate and detune values has been combined with global rate and detune values.

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

volume :number

Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume).

Type:
  • number
Since: 3.0.0
Default Value:
  • 1
Source: src/sound/html5/HTML5AudioSound.js (Line 629)

Methods


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.HTML5AudioSound

addMarker(marker)

Adds a marker into the current sound. A marker is represented by name, start time, duration, and optionally config object. This allows you to bundle multiple sounds together into a single audio file and use markers to jump between them for playback.

Parameters:
Name Type Description
marker Phaser.Types.Sound.SoundMarker

Marker object.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 184)
Returns:

Whether the marker was added successfully.

Type
boolean

<protected> applyConfig()

Method used internally for applying config values to some of the sound properties.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 409)

<protected> calculateRate()

Method used internally to calculate total playback rate of the sound.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 562)

destroy()

Calls Phaser.Sound.BaseSound#destroy method and cleans up all HTML5 Audio related stuff.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 513)

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)>

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.HTML5AudioSound

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.HTML5AudioSound

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.HTML5AudioSound

pause()

Pauses the sound.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 134)
Fires:
Returns:

Whether the sound was paused successfully.

Type
boolean

play( [markerName] [, config])

Play this sound, or a marked section of it. It always plays the sound from the start. If you want to start playback from a specific time you can set 'seek' setting of the config object, provided to this call, to that value.

Parameters:
Name Type Argument Default Description
markerName string | Phaser.Types.Sound.SoundConfig <optional>
''

If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object.

config Phaser.Types.Sound.SoundConfig <optional>

Optional sound config object to be applied to this marker or entire sound if no marker name is provided. It gets memorized for future plays of current section of the sound.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 97)
Fires:
Returns:

Whether the sound started playing successfully.

Type
boolean

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.HTML5AudioSound

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.HTML5AudioSound

removeMarker(markerName)

Removes a marker from the sound.

Parameters:
Name Type Description
markerName string

The name of the marker to remove.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 261)
Returns:

Removed marker object or 'null' if there was no marker with provided name.

Type
Phaser.Types.Sound.SoundMarker

<protected> resetConfig()

Method used internally for resetting values of some of the config properties.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 426)

resume()

Resumes the sound.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 170)
Fires:
Returns:

Whether the sound was resumed successfully.

Type
boolean

setDetune(value)

Sets the detune value of this Sound, given 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
Source: src/sound/html5/HTML5AudioSound.js (Line 770)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setLoop(value)

Sets the loop state of this Sound.

Parameters:
Name Type Description
value boolean

true to loop this sound, false to not loop it.

Since: 3.4.0
Source: src/sound/html5/HTML5AudioSound.js (Line 902)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setMute(value)

Sets the muted state of this Sound.

Parameters:
Name Type Description
value boolean

true to mute this sound, false to unmute it.

Since: 3.4.0
Source: src/sound/html5/HTML5AudioSound.js (Line 611)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setPan(value)

Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).

Has no audible effect on HTML5 Audio Sound, but still generates the PAN Event.

Parameters:
Name Type Description
value number

The pan of the sound. A value between -1 (full left pan) and 1 (full right pan).

Since: 3.50.0
Source: src/sound/html5/HTML5AudioSound.js (Line 946)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setRate(value)

Sets the playback rate of this Sound.

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

The playback rate at of this Sound.

Since: 3.3.0
Source: src/sound/html5/HTML5AudioSound.js (Line 714)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setSeek(value)

Seeks to a specific point in this sound.

Parameters:
Name Type Description
value number

The point in the sound to seek to.

Since: 3.4.0
Source: src/sound/html5/HTML5AudioSound.js (Line 849)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

setVolume(value)

Sets the volume of this Sound.

Parameters:
Name Type Description
value number

The volume of the sound.

Since: 3.4.0
Source: src/sound/html5/HTML5AudioSound.js (Line 660)
Fires:
Returns:

This Sound instance.

Type
Phaser.Sound.HTML5AudioSound

shutdown()

Removes all listeners.

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

stop()

Stop playing this sound.

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 207)
Fires:
Returns:

Whether the sound was stopped successfully.

Type
boolean

<protected> update(time)

Update method called automatically by sound manager on every game step.

Parameters:
Name Type Description
time number

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

Since: 3.0.0
Overrides:
Source: src/sound/html5/HTML5AudioSound.js (Line 444)
Fires:

updateMarker(marker)

Updates previously added marker.

Parameters:
Name Type Description
marker Phaser.Types.Sound.SoundMarker

Marker object with updated values.

Since: 3.0.0
Inherited From:
Source: src/sound/BaseSound.js (Line 231)
Returns:

Whether the marker was updated successfully.

Type
boolean