SudokuFX
Loading...
Searching...
No Matches
fr.softsf.sudokufx.service.ui.AudioService Class Reference

Service managing audio playback for the application. More...

+ Collaboration diagram for fr.softsf.sudokufx.service.ui.AudioService:

Public Member Functions

synchronized boolean isMuted ()
 Checks if audio is currently muted.
 
synchronized void muteAll ()
 Mutes all audio (song and effects).
 
synchronized void playEffect (@Nullable File effectFile, String key)
 Plays a short sound effect.
 
synchronized void playSong (@Nullable File songFile)
 Plays a song in a loop.
 
synchronized void setEffectVolume (String key, double volume)
 Sets the volume for a specific effect (when not muted).
 
synchronized void setMuted (boolean isMuted)
 Sets the muted state.
 
synchronized void setSongVolume (double volume)
 Sets the volume for the song (when not muted).
 
synchronized void stopAll ()
 Stops and disposes all audio resources.
 
synchronized void stopSong ()
 Stops and disposes the song player.
 
synchronized void unmuteAll ()
 Unmutes all audio and restores original volumes.
 

Private Attributes

final Map< String, MediaPlayer > effectsPlayers = new HashMap<>()
 
boolean isMuted = false
 
final Map< String, Double > originalEffectVolumes = new HashMap<>()
 
double originalSongVolume = 1.0
 
MediaPlayer songPlayer
 

Static Private Attributes

static final Logger LOG = LoggerFactory.getLogger(AudioService.class)
 
static final Set< String > VALID_EFFECT_KEYS = Set.of("button_click", "case_click")
 

Detailed Description

Service managing audio playback for the application.

Supports song and short sound effects, with automatic disposal of MediaPlayer instances to prevent memory leaks.

Member Function Documentation

◆ isMuted()

synchronized boolean fr.softsf.sudokufx.service.ui.AudioService.isMuted ( )

Checks if audio is currently muted.

Returns
true if all audio is muted

◆ muteAll()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.muteAll ( )

Mutes all audio (song and effects).

◆ playEffect()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.playEffect ( @Nullable File effectFile,
String key )

Plays a short sound effect.

Reuses an existing MediaPlayer for the given key if present. Automatically disposes the MediaPlayer after playback.

Parameters
effectFilethe sound effect file
keya unique identifier for the effect
Exceptions
IllegalArgumentExceptionif effectFile is null
IllegalArgumentExceptionif key is null, empty, or blank
IllegalArgumentExceptionif key is not in the valid effect keys set
IllegalArgumentExceptionif the file URI is invalid
RuntimeExceptionif the media file cannot be loaded or played

◆ playSong()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.playSong ( @Nullable File songFile)

Plays a song in a loop.

Stops and disposes any existing song player.

Parameters
songFilethe song audio file
Exceptions
IllegalArgumentExceptionif songFile is null
IllegalArgumentExceptionif the file URI is invalid
RuntimeExceptionif the media file cannot be loaded or played

◆ setEffectVolume()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.setEffectVolume ( String key,
double volume )

Sets the volume for a specific effect (when not muted).

Parameters
keythe effect key
volumevolume level (0.0 to 1.0)
Exceptions
IllegalArgumentExceptionif key is null, empty, or blank
IllegalArgumentExceptionif key is not in the valid effect keys set

◆ setMuted()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.setMuted ( boolean isMuted)

Sets the muted state.

Used for initialization from database.

Parameters
isMutedtrue to mute all audio, false to unmute
+ Here is the call graph for this function:

◆ setSongVolume()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.setSongVolume ( double volume)

Sets the volume for the song (when not muted).

Parameters
volumevolume level (0.0 to 1.0)

◆ stopAll()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.stopAll ( )

Stops and disposes all audio resources.

+ Here is the call graph for this function:

◆ stopSong()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.stopSong ( )

Stops and disposes the song player.

◆ unmuteAll()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.unmuteAll ( )

Unmutes all audio and restores original volumes.

Member Data Documentation

◆ effectsPlayers

final Map<String, MediaPlayer> fr.softsf.sudokufx.service.ui.AudioService.effectsPlayers = new HashMap<>()
private

◆ isMuted

boolean fr.softsf.sudokufx.service.ui.AudioService.isMuted = false
private

◆ LOG

final Logger fr.softsf.sudokufx.service.ui.AudioService.LOG = LoggerFactory.getLogger(AudioService.class)
staticprivate

◆ originalEffectVolumes

final Map<String, Double> fr.softsf.sudokufx.service.ui.AudioService.originalEffectVolumes = new HashMap<>()
private

◆ originalSongVolume

double fr.softsf.sudokufx.service.ui.AudioService.originalSongVolume = 1.0
private

◆ songPlayer

MediaPlayer fr.softsf.sudokufx.service.ui.AudioService.songPlayer
private

◆ VALID_EFFECT_KEYS

final Set<String> fr.softsf.sudokufx.service.ui.AudioService.VALID_EFFECT_KEYS = Set.of("button_click", "case_click")
staticprivate

The documentation for this class was generated from the following file: