Skip to main content

FlixelSoundManager

View source

class

org.flixelgdx.audio.FlixelSoundManager

public class FlixelSoundManager implements FlixelDestroyable, Disposable

Central manager for all audio. FlixelSound instances, master volume, sound groups (SFX and music), and focus-based pause/resume.

Access via Flixel.sound. Supports separate groups for sound effects and music, global master volume, and automatic pause when the game loses focus (and resume when it regains focus).

For internal paths, FlixelSoundManager.play(String) and FlixelSoundManager.playMusic(String) resolve audio through Flixel.ensureAssets(), which uses a loaded FlixelSoundSource when present, otherwise enqueue and block-load that source before creating a FlixelSound. External paths still bypass the asset manager and hit the backend directly.

Constructors

FlixelSoundManager(Factory)

public FlixelSoundManager(Factory factory)

Constructs a new audio manager using the given backend factory.

Parameters:

NameDescription
factoryThe platform-specific sound backend factory.

Fields

music

public FlixelSound music

Methods

resetSession()

public void resetSession()

Stops session audio and rebuilds SFX and music groups on the existing engine.

Use this instead of FlixelSoundManager.destroy() so the native backend is not torn down and re-created in one frame (which can break PulseAudio and similar backends) unless you know for sure you don't want to use the audio system anymore.


clearNonPersist()

public void clearNonPersist()

Destroys all non-persistent FlixelSound instances tracked by this manager, including the current music track if it is not persistent.

Called automatically by Flixel.switchState on every state switch when the asset mode is FlixelAssetMode.STANDARD or FlixelAssetMode.AGGRESSIVE. Sounds whose FlixelSound.isPersist() flag is set survive the switch unchanged.

Sounds that were already destroyed (for example, via FlixelSound.setAutoDestroy(boolean)) are pruned from the tracking list without being double-destroyed.


getFactory()

public Factory getFactory()

Returns the underlying backend factory for advanced use.

Returns: The backend factory powering this manager.


getSfxGroup()

public Object getSfxGroup()

Returns the SFX group handle. Use for playing sounds or custom sounds that should be categorised as SFX.

Returns: The SFX group handle.


getMusicGroup()

public Object getMusicGroup()

Returns the music group handle. Used by FlixelSoundManager.playMusic(String).

Returns: The music group handle.


getSoundsGroup()

public Object getSoundsGroup()

Returns the default group used when no group is specified (SFX group).

Returns: The SFX group handle.


getMasterVolume()

public float getMasterVolume()

Returns the current master volume.

Returns: Master volume in [0, 1].


setMasterVolume(float)

public float setMasterVolume(float volume)

Sets the global master volume applied to all sounds.

Parameters:

NameDescription
volumeNew master volume (values outside [0, 1] are clamped).

Returns: The clamped master volume.


changeMasterVolume(float)

public float changeMasterVolume(float amount)

Changes the global master volume by the given amount.

Parameters:

NameDescription
amountThe amount to change the master volume by.

Returns: The new master volume.


play(String)

public FlixelSound play(String path)

Plays a new sound effect (SFX group).

Parameters:

NameDescription
pathInternal asset key / path, or external path when external is true.

Returns: The new FlixelSound instance.


play(String, float)

public FlixelSound play(String path, float volume)

Plays a new sound effect.

Parameters:

NameDescription
pathPath to the sound.
volumeVolume to play with.

Returns: The new FlixelSound instance.


play(String, float, boolean)

public FlixelSound play(String path, float volume, boolean looping)

Plays a new sound effect.

Parameters:

NameDescription
pathPath to the sound.
volumeVolume to play with.
loopingWhether to loop.

Returns: The new FlixelSound instance.


play(String, float, boolean, Object)

public FlixelSound play(String path, float volume, boolean looping, Object group)

Plays a new sound effect.

Parameters:

NameDescription
pathPath to the sound.
volumeVolume to play with.
loopingWhether to loop.
groupSound group, or null to use the default SFX group.

Returns: The new FlixelSound instance.


play(String, float, boolean, Object, boolean)

public FlixelSound play(String path, float volume, boolean looping, Object group, boolean external)

Plays a new sound effect.

Parameters:

NameDescription
pathPath to the sound.
volumeVolume to play with.
loopingWhether to loop.
groupSound group, or null to use the default SFX group.
externalIf true, the path is used as-is (for external files).

Returns: The new FlixelSound instance.


playMusic(String)

public FlixelSound playMusic(String path)

Sets and plays the current music (music group). Stops any previous music.

Parameters:

NameDescription
pathPath to the music file.

Returns: The new music FlixelSound instance.


playMusic(String, float)

public FlixelSound playMusic(String path, float volume)

Sets and plays the current music. Stops any previous music.

Parameters:

NameDescription
pathPath to the music file.
volumeVolume.

Returns: The new music FlixelSound instance.


playMusic(String, float, boolean)

public FlixelSound playMusic(String path, float volume, boolean looping)

Sets and plays the current music. Stops any previous music.

Parameters:

NameDescription
pathPath to the music file.
volumeVolume.
loopingWhether to loop.

Returns: The new music FlixelSound instance.


playMusic(String, float, boolean, boolean)

public FlixelSound playMusic(String path, float volume, boolean looping, boolean external)

Sets and plays the current music. Stops any previous music.

Parameters:

NameDescription
pathPath to the music file.
volumeVolume.
loopingWhether to loop.
externalIf true, the path is used as-is (e.g. for mobile external storage).

Returns: The new music FlixelSound instance.


pause()

public void pause()

Pauses all currently playing sounds. Used when the game loses focus or is minimized. Only sounds that were playing are paused; they can be resumed with FlixelSoundManager.resume().


resume()

public void resume()

Resumes all sounds that were paused by FlixelSoundManager.pause(). Called when the game regains focus.


destroy()

public void destroy()

dispose()

public final void dispose()