Class AudioManager

java.lang.Object
com.csse3200.game.services.AudioManager

public class AudioManager extends Object
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 Details

    • playSound

      public static void playSound(String soundPath)
      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

      public static void stopSound(String soundPath)
      Stop the specified sound if it's currently playing.
      Parameters:
      soundPath - The path of the sound file to be stopped.
    • playMusic

      public static void playMusic(String musicPath, boolean looping)
      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()