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 (File effectFile, String key) throws ResourceLoadException
 Plays a short sound effect.
 
synchronized void playSong (File songFile) throws ResourceLoadException
 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 ( File effectFile,
String key ) throws ResourceLoadException

Plays a short sound effect.

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

The provided effectFile must not be null. The key must be one of the VALID_EFFECT_KEYS. The method throws a ResourceLoadException if the media file cannot be loaded or played.

effectFile is required and cannot be null. key cannot be null, blank, or invalid; otherwise an IllegalArgumentException is thrown.

Parameters
effectFilethe sound effect file; must not be null
keya unique identifier for the effect; must be in VALID_EFFECT_KEYS, non-blank
Exceptions
NullPointerExceptionif effectFile is null
IllegalArgumentExceptionif key is null, blank, or not in VALID_EFFECT_KEYS
ResourceLoadExceptionif the media file cannot be loaded or played

◆ playSong()

synchronized void fr.softsf.sudokufx.service.ui.AudioService.playSong ( File songFile) throws ResourceLoadException

Plays a song in a loop.

Stops and disposes any existing song player.

The provided songFile must not be null. If the file cannot be loaded or played, a ResourceLoadException is thrown.

Parameters
songFilethe song audio file; must not be null
Exceptions
NullPointerExceptionif songFile is null
ResourceLoadExceptionif 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: