Package com.csse3200.game.services
Class AudioManager
java.lang.Object
com.csse3200.game.services.AudioManager
AudioManager is a service for managing all game audio, including music and sound effects.
It interacts with the ServiceLocator to retrieve the ResourceService for sound management.
-
Method Summary
Modifier and TypeMethodDescriptionstatic float
static float
static float
Get the current music volume level.static float
Get the current sound volume level.static boolean
isMuted()
Check if the audio is muted.static void
Mute both music and sound.static void
Play the specified music with the current music volume level, retrieved via ResourceService.static void
Play the specified sound at the current sound volume level, retrieved via ResourceService.static void
setMusicVolume
(float volume) Set the volume for all music.static void
setSoundVolume
(float volume) Set the volume for all sounds.static void
Stop the currently playing music.static void
Stop the specified sound if it's currently playing.static void
Unmute both music and sound.
-
Method Details
-
playSound
Play the specified sound at the current sound volume level, retrieved via ResourceService.- Parameters:
soundPath
- The path of the sound file to be played.
-
stopSound
Stop the specified sound if it's currently playing.- Parameters:
soundPath
- The path of the sound file to be stopped.
-
playMusic
Play the specified music with the current music volume level, retrieved via ResourceService.- Parameters:
musicPath
- The path of the music file to be played.looping
- True if the music should loop, false otherwise.
-
muteAudio
public static void muteAudio()Mute both music and sound. This will set the volume to 0 but retain the previous volume. -
unmuteAudio
public static void unmuteAudio()Unmute both music and sound. This will restore the volume to its previous levels. -
isMuted
public static boolean isMuted()Check if the audio is muted.- Returns:
- True if audio is muted, false otherwise.
-
stopMusic
public static void stopMusic()Stop the currently playing music. -
setMusicVolume
public static void setMusicVolume(float volume) Set the volume for all music. This will apply to the currently playing music if any. If the audio is muted, it will override this and set the volume to 0.- Parameters:
volume
- Volume level (0.0 to 1.0)
-
setSoundVolume
public static void setSoundVolume(float volume) Set the volume for all sounds. This will apply to currently playing sounds as well. If the audio is muted, it will override this and set the volume to 0.- Parameters:
volume
- Volume level (0.0 to 1.0)
-
getMusicVolume
public static float getMusicVolume()Get the current music volume level.- Returns:
- The current music volume (0.0 to 1.0)
-
getSoundVolume
public static float getSoundVolume()Get the current sound volume level.- Returns:
- The current sound volume (0.0 to 1.0)
-
getDesiredMusicVolume
public static float getDesiredMusicVolume() -
getDesiredSoundVolume
public static float getDesiredSoundVolume()
-