FlixelSoundManager
View sourceclass
org.flixelgdx.audio.FlixelSoundManager
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)
Constructs a new audio manager using the given backend factory.
Parameters:
| Name | Description |
|---|---|
factory | The platform-specific sound backend factory. |
Fields
music
Methods
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()
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()
Returns the underlying backend factory for advanced use.
Returns: The backend factory powering this manager.
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()
Returns the music group handle. Used by FlixelSoundManager.playMusic(String).
Returns: The music group handle.
getSoundsGroup()
Returns the default group used when no group is specified (SFX group).
Returns: The SFX group handle.
getMasterVolume()
Returns the current master volume.
Returns: Master volume in [0, 1].
setMasterVolume(float)
Sets the global master volume applied to all sounds.
Parameters:
| Name | Description |
|---|---|
volume | New master volume (values outside [0, 1] are clamped). |
Returns: The clamped master volume.
changeMasterVolume(float)
Changes the global master volume by the given amount.
Parameters:
| Name | Description |
|---|---|
amount | The amount to change the master volume by. |
Returns: The new master volume.
play(String)
Plays a new sound effect (SFX group).
Parameters:
| Name | Description |
|---|---|
path | Internal asset key / path, or external path when external is true. |
Returns: The new FlixelSound instance.
play(String, float)
Plays a new sound effect.
Parameters:
| Name | Description |
|---|---|
path | Path to the sound. |
volume | Volume to play with. |
Returns: The new FlixelSound instance.
play(String, float, boolean)
Plays a new sound effect.
Parameters:
| Name | Description |
|---|---|
path | Path to the sound. |
volume | Volume to play with. |
looping | Whether to loop. |
Returns: The new FlixelSound instance.
play(String, float, boolean, Object)
Plays a new sound effect.
Parameters:
| Name | Description |
|---|---|
path | Path to the sound. |
volume | Volume to play with. |
looping | Whether to loop. |
group | Sound group, or null to use the default SFX group. |
Returns: The new FlixelSound instance.
play(String, float, boolean, Object, boolean)
Plays a new sound effect.
Parameters:
| Name | Description |
|---|---|
path | Path to the sound. |
volume | Volume to play with. |
looping | Whether to loop. |
group | Sound group, or null to use the default SFX group. |
external | If true, the path is used as-is (for external files). |
Returns: The new FlixelSound instance.
playMusic(String)
Sets and plays the current music (music group). Stops any previous music.
Parameters:
| Name | Description |
|---|---|
path | Path to the music file. |
Returns: The new music FlixelSound instance.
playMusic(String, float)
Sets and plays the current music. Stops any previous music.
Parameters:
| Name | Description |
|---|---|
path | Path to the music file. |
volume | Volume. |
Returns: The new music FlixelSound instance.
playMusic(String, float, boolean)
Sets and plays the current music. Stops any previous music.
Parameters:
| Name | Description |
|---|---|
path | Path to the music file. |
volume | Volume. |
looping | Whether to loop. |
Returns: The new music FlixelSound instance.
playMusic(String, float, boolean, boolean)
Sets and plays the current music. Stops any previous music.
Parameters:
| Name | Description |
|---|---|
path | Path to the music file. |
volume | Volume. |
looping | Whether to loop. |
external | If true, the path is used as-is (e.g. for mobile external storage). |
Returns: The new music FlixelSound instance.
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()
Resumes all sounds that were paused by FlixelSoundManager.pause(). Called when the game regains focus.