![]() |
SudokuFX
|
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") |
Service managing audio playback for the application.
Supports song and short sound effects, with automatic disposal of MediaPlayer instances to prevent memory leaks.
| synchronized boolean fr.softsf.sudokufx.service.ui.AudioService.isMuted | ( | ) |
Checks if audio is currently muted.
| synchronized void fr.softsf.sudokufx.service.ui.AudioService.muteAll | ( | ) |
Mutes all audio (song and effects).
| 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.
| effectFile | the sound effect file; must not be null |
| key | a unique identifier for the effect; must be in VALID_EFFECT_KEYS, non-blank |
| NullPointerException | if effectFile is null |
| IllegalArgumentException | if key is null, blank, or not in VALID_EFFECT_KEYS |
| ResourceLoadException | if the media file cannot be loaded or played |
| 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.
| songFile | the song audio file; must not be null |
| NullPointerException | if songFile is null |
| ResourceLoadException | if the media file cannot be loaded or played |
| synchronized void fr.softsf.sudokufx.service.ui.AudioService.setEffectVolume | ( | String | key, |
| double | volume ) |
Sets the volume for a specific effect (when not muted).
| key | the effect key |
| volume | volume level (0.0 to 1.0) |
| IllegalArgumentException | if key is null, empty, or blank |
| IllegalArgumentException | if key is not in the valid effect keys set |
| synchronized void fr.softsf.sudokufx.service.ui.AudioService.setMuted | ( | boolean | isMuted | ) |
Sets the muted state.
Used for initialization from database.
| isMuted | true to mute all audio, false to unmute |
Here is the call graph for this function:| synchronized void fr.softsf.sudokufx.service.ui.AudioService.setSongVolume | ( | double | volume | ) |
Sets the volume for the song (when not muted).
| volume | volume level (0.0 to 1.0) |
| synchronized void fr.softsf.sudokufx.service.ui.AudioService.stopAll | ( | ) |
Stops and disposes all audio resources.
Here is the call graph for this function:| synchronized void fr.softsf.sudokufx.service.ui.AudioService.stopSong | ( | ) |
Stops and disposes the song player.
| synchronized void fr.softsf.sudokufx.service.ui.AudioService.unmuteAll | ( | ) |
Unmutes all audio and restores original volumes.
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
staticprivate |