Skip to content
ClassAudio System@public

FlxAudioManager

Owns the audio backend, the music singleton, and the sound-effects group.

Registered on the FlxContext service map via FLX_AUDIO_SERVICE. FlxG resolves it to expose FlxG.music, FlxG.sounds, FlxG.play(), FlxG.playMusic(), FlxG.stream(), FlxG.volume, FlxG.mute, FlxG.pauseSounds(), and FlxG.resumeSounds().

ts
export declare class FlxAudioManager implements FlxAudioService

Constructors

ts
constructor(context: FlxContext, backend: FlxAudioBackend)

Constructs a new instance of the FlxAudioManager class

ParameterTypeDescription
contextFlxContext-
backendFlxAudioBackend-

Properties

PropertyModifiersTypeDescription
music-FlxSound | null-
musicGroupreadonlyFlxSoundGroup-
mute-boolean-
soundGroupreadonlyFlxSoundGroup-
soundsreadonlyFlxGroup-
volume-number-

Methods

destroy()

ts
destroy(): void

Full teardown.

Returns: void

destroySounds()

ts
destroySounds(forceDestroy: boolean): void

Remove non-survive sounds on state switch.

Parameters:

ParameterTypeDescription
forceDestroybooleanIf true, destroy survive sounds too.

Returns: void

onChange()

ts
onChange(listener: (state: FlxAudioState) => void): () => void

Subscribe to master audio preference changes.

Parameters:

ParameterTypeDescription
listener(state: FlxAudioState) => void-

Returns: () => void

pauseSounds()

ts
pauseSounds(): void

Pause all sounds and music.

Returns: void

play()

ts
play(source: unknown, volume?: number, loop?: boolean, autoDestroy?: boolean, group?: FlxSoundGroup): FlxSound

Play a sound effect.

Parameters:

ParameterTypeDescription
sourceunknownAudioBuffer, HTMLAudioElement, or URL string.
volumenumberPer-instance volume (0–1). Defaults to 1.
loopbooleanWhether to loop. Defaults to false.
autoDestroybooleanWhether to auto-destroy when done. Defaults to true.
groupFlxSoundGroup-

Returns: FlxSound

playMusic()

ts
playMusic(source: unknown, volume?: number, group?: FlxSoundGroup): void

Play music, stopping the current track.

Parameters:

ParameterTypeDescription
sourceunknownAudioBuffer, HTMLAudioElement, or URL string.
volumenumberVolume (0–1). Defaults to 1.
groupFlxSoundGroup-

Returns: void

resumeSounds()

ts
resumeSounds(): void

Resume all sounds and music.

Returns: void

stream()

ts
stream(url: string, volume?: number, loop?: boolean, autoDestroy?: boolean, group?: FlxSoundGroup): FlxSound

Play a streaming sound from a URL.

Parameters:

ParameterTypeDescription
urlstringThe streaming URL.
volumenumberPer-instance volume (0–1). Defaults to 1.
loopbooleanWhether to loop. Defaults to false.
autoDestroybooleanWhether to auto-destroy when done. Defaults to true.
groupFlxSoundGroup-

Returns: FlxSound

updateSounds()

ts
updateSounds(elapsed: number): void

Called by FlxGame.step() to advance fades, proximity, and auto-destroy.

Parameters:

ParameterTypeDescription
elapsednumber-

Returns: void

Released under the MIT License.