Package view.audio
Class AudioPlayer
java.lang.Object
view.audio.AudioPlayer
Manages audio playback for the game, including songs and sound effects.
Implements the singleton pattern to ensure a single instance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic AudioPlayerReturns the singleton instance of the AudioPlayer.voidPlays the intro song and sets up a listener to play the main song after the intro ends.voidPlays the main playing song in a loop.voidplaySoundEffect(int soundEffectID) Plays the specified sound effect.voidsetVolume(float volume) Sets the volume for both songs and sound effects.voidStarts the current song if it's not already playing.voidstopSong()Stops the current song.
-
Method Details
-
getInstance
Returns the singleton instance of the AudioPlayer.- Returns:
- the singleton instance
-
setVolume
public void setVolume(float volume) Sets the volume for both songs and sound effects.- Parameters:
volume- the volume level to set
-
stopSong
public void stopSong()Stops the current song. -
startSong
public void startSong()Starts the current song if it's not already playing. -
playIntroSong
public void playIntroSong()Plays the intro song and sets up a listener to play the main song after the intro ends. -
playPlayingSong
public void playPlayingSong()Plays the main playing song in a loop. -
playSoundEffect
public void playSoundEffect(int soundEffectID) Plays the specified sound effect.- Parameters:
soundEffectID- the ID of the sound effect to play
-