Class AudioPlayer

java.lang.Object
javatro.audioplayer.AudioPlayer

public class AudioPlayer extends Object
The AudioPlayer class provides functionality for playing, stopping, and switching audio files. This class is implemented as a singleton to ensure only one instance of the player is active at any given time. It supports looping audio files continuously.
  • Method Details

    • getInstance

      public static AudioPlayer getInstance()
      Returns the singleton instance of AudioPlayer.
      Returns:
      The singleton AudioPlayer instance.
    • playAudio

      public void playAudio(String audioPath)
      Plays an audio file. If the specified audio file is already playing, this method returns without restarting it.
      Parameters:
      audioPath - The path of the audio file to play. Must not be null or empty.
    • switchAudio

      public void switchAudio(String newAudioPath)
      Switches to a new audio file, stopping any currently playing audio.
      Parameters:
      newAudioPath - The path of the new audio file to play. Must not be null or empty.
    • stopAudio

      public void stopAudio()
      Stops the currently playing audio, if any, and properly cleans up resources.
    • isPlaying

      public boolean isPlaying()
      Checks if an audio file is currently playing.
      Returns:
      true if an audio file is playing, false otherwise.
    • getCurrentAudioPath

      public String getCurrentAudioPath()
      Returns the path of the currently playing audio file.
      Returns:
      The path of the currently playing audio file, or null if no audio is playing.