Package javatro.audioplayer
Class AudioPlayer
java.lang.Object
javatro.audioplayer.AudioPlayer
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 Summary
Modifier and TypeMethodDescriptionReturns the path of the currently playing audio file.static AudioPlayerReturns the singleton instance ofAudioPlayer.booleanChecks if an audio file is currently playing.voidPlays an audio file.voidStops the currently playing audio, if any, and properly cleans up resources.voidswitchAudio(String newAudioPath) Switches to a new audio file, stopping any currently playing audio.
-
Method Details
-
getInstance
Returns the singleton instance ofAudioPlayer.- Returns:
- The singleton
AudioPlayerinstance.
-
playAudio
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
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:
trueif an audio file is playing,falseotherwise.
-
getCurrentAudioPath
Returns the path of the currently playing audio file.- Returns:
- The path of the currently playing audio file, or
nullif no audio is playing.
-