Reference to the WebAudio Sound Manager that owns this Sound instance.
Asset key for the sound.
Optionalconfig: SoundConfig
An optional config object containing default sound settings. Default {}.
Audio buffer containing decoded data of the audio asset to be played.
ReadonlycurrentCurrently playing marker. 'null' if whole sound is playing.
ReadonlydurationA value representing the duration, in seconds. It could be total sound duration or a marker duration.
ReadonlyhasUsed for keeping track when sound source playback has ended so its state can be updated accordingly.
ReadonlyhasUsed for keeping track when sound source has looped so its state can be updated accordingly.
ReadonlyisFlag indicating if sound is currently paused.
ReadonlyisFlag indicating if sound is currently playing.
ReadonlykeyAsset key for the sound.
Flag indicating whether or not the sound or current sound marker will loop.
A reference to a second audio source used for gapless looped playback.
The time at which the sound loop source should actually start playback.
Based on BaseAudioContext.currentTime value.
Local reference to the sound manager.
ReadonlymarkersObject containing markers definitions.
Gets or sets the muted state of this sound.
Gain node responsible for controlling this sound's muting.
Gets or sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).
Always returns zero on iOS / Safari as it doesn't support the stereo panner node.
Panner node responsible for controlling this sound's pan.
Only created if the device supports it. Might not work on iOS / Safari.
Flag indicating if destroy method was called on this sound.
The time at which the sound should have started playback from the beginning.
Treat this property as read-only.
Based on BaseAudioContext.currentTime value.
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 audio's playback speed.
An array where we keep track of all rate updates during playback.
Treat this property as read-only.
Array of object types: { time: number, rate: 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.
A reference to an audio source node used for playing back audio from audio data stored in Phaser.Sound.WebAudioSound#audioBuffer.
The Stereo Spatial Panner node.
If the Spatial Panner node has been set to track a vector or Game Object, this retains a reference to it.
The time at which the sound source should have actually started playback.
Treat this property as read-only.
Based on BaseAudioContext.currentTime value.
ReadonlytotalThe total duration of the sound in seconds.
ReadonlytotalA property that holds the value of sound's actual playback rate, after its rate and detune values have been combined with global rate and detune values.
Gets or sets the volume of this sound, a value between 0 (silence) and 1 (full volume).
Gain node responsible for controlling this sound's volume.
Gets or sets the x position of this Sound in Spatial Audio space.
This only has any effect if the sound was created with a SpatialSoundConfig object.
Also see the WebAudioSoundManager.setListenerPosition method.
If you find that the sound becomes too quiet, too quickly, as it moves away from
the listener, then try different refDistance property values when configuring
the spatial sound.
Gets or sets the y position of this Sound in Spatial Audio space.
This only has any effect if the sound was created with a SpatialSoundConfig object.
Also see the WebAudioSoundManager.setListenerPosition method.
If you find that the sound becomes too quiet, too quickly, as it moves away from
the listener, then try different refDistance property values when configuring
the spatial sound.
Add a listener for a given event.
The event name.
The listener function.
Optionalcontext: any
The context to invoke the listener with. Default this.
this.
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.
Marker object.
Whether the marker was added successfully.
Method used internally for applying config values to some of the sound properties.
Method used internally to calculate total playback rate of the sound.
This method is only used internally and it creates a looping buffer source.
This method is only used internally and it creates a buffer source.undefined
undefined
Calls Phaser.Sound.BaseSound#destroy method and disconnects all Web Audio API nodes, releasing all references to audio resources.
Calls each of the listeners registered for a given event.
The event name.
Additional arguments that will be passed to the event handler.
true if the event had listeners, else false.
Return an array listing the events for which the emitter has registered listeners.undefined
undefined
Method used internally for calculating current playback time of a playing sound.
Method used internally for calculating the time at which the loop source should start playing.
Return the number of listeners listening to a given event.
The event name.
The number of listeners.
Return the listeners registered for a given event.
The event name.
The registered listeners.
Remove the listeners of a given event.
The event name.
Optionalfn: Function
Only remove the listeners that match this function.
Optionalcontext: any
Only remove the listeners that have this context.
Optionalonce: boolean
Only remove one-time listeners.
this.
Add a listener for a given event.
The event name.
The listener function.
Optionalcontext: any
The context to invoke the listener with. Default this.
this.
Add a one-time listener for a given event. The listener is automatically removed the first time the event is emitted, so it will never be called more than once.
The event name.
The listener function.
Optionalcontext: any
The context to invoke the listener with. Default this.
this.
Pauses the sound.undefined
Whether the sound was paused successfully.
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.
If you want to play the same sound simultaneously, then you need to create another instance of it and play that Sound.
OptionalmarkerName: string | SoundConfig
If you want to play a marker then provide the marker name here. Alternatively, this parameter can be a SoundConfig object. Default ''.
Optionalconfig: SoundConfig
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.
Whether the sound started playing successfully.
Remove all listeners, or those of the specified event.
Optionalevent: string | symbol
The event name.
this.
Remove the listeners of a given event.
The event name.
Optionalfn: Function
Only remove the listeners that match this function.
Optionalcontext: any
Only remove the listeners that have this context.
Optionalonce: boolean
Only remove one-time listeners.
this.
Removes a marker from the sound.
The name of the marker to remove.
Removed marker object or 'null' if there was no marker with provided name.
Method used internally for resetting values of some of the config properties.
Resumes the sound.undefined
Whether the sound was resumed successfully.
Sets the loop state of this Sound.
true to loop this sound, false to not loop it.
This Sound instance.
Sets the muted state of this Sound.
true to mute this sound, false to unmute it.
This Sound instance.
Sets the pan of this sound, a value between -1 (full left pan) and 1 (full right pan).
Note: iOS / Safari doesn't support the stereo panner node.
The pan of the sound. A value between -1 (full left pan) and 1 (full right pan).
This Sound instance.
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 audio's playback speed.
The playback rate of this Sound.
This Sound instance.
Seeks to a specific point in this sound.
The point in the sound to seek to, in seconds.
This Sound instance.
Sets the volume of this Sound.
The volume of the sound, between 0 (silence) and 1 (full volume).
This Sound instance.
Removes all listeners from this EventEmitter. This method is called automatically by the Scene Systems when the parent Scene shuts down, ensuring that all event bindings are cleared and no stale references remain.
Stop playing this sound.undefined
Whether the sound was stopped successfully.
This method is only used internally and it stops and removes a buffer source.
This method is only used internally and it stops and removes a looping buffer source.
Update method called automatically by sound manager on every game step.
Updates a previously added marker with new values from the provided marker object.
Marker object with updated values.
Whether the marker was updated successfully.
A Web Audio API based Sound instance that can be played, paused, stopped, looped, and have its volume, rate, detune, pan, and spatial position controlled in real time.
This is the default sound implementation used by Phaser when the Web Audio API is available in the browser. It uses an AudioBufferSourceNode internally, with a chain of GainNodes for volume and muting, an optional StereoPannerNode for stereo panning, and an optional PannerNode for 3D spatial audio positioning.
If the Web Audio API is unavailable, Phaser will fall back to the HTML5 Audio implementation. You do not typically create WebAudioSound instances directly; instead, use the Sound Manager via
this.sound.add(key)within a Scene.