Package com.csse3200.game.services.sound
Interface MusicService
- All Known Implementing Classes:
BackgroundMusicService
,EffectsMusicService
public interface MusicService
The MusicService interface is implemented by the BackgroundMusicService and the EffectMusicService
Both these classes have similar function definitions, however the implementations of these functions differs
based on the needs of the two types of audio played in the game.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose all the currently loaded SoundFiles from memory before closing the service.boolean
isMuted()
Check if the current MusicService is currently muted.boolean
Checks if a certain SoundFile is playing.void
loadSounds
(List<SoundFile> sounds) Given a list of SoundFiles, load them all into memory.void
Pause a SoundFile that is currently playing without losing the progress of that track.long
A convenience method to play a sound without explicitly controlling the loop propertylong
Play a given SoundFile, with it optionally loopingvoid
setMuted
(boolean muted) Mutes the playback of a given MusicService.void
Stop a SoundFile that is currently playing.
-
Method Details
-
play
Play a given SoundFile, with it optionally looping- Parameters:
sound
- - An enum value that implements the SoundFile interfacelooping
- - A flag to control if the sound loops- Returns:
- a long integer corresponding to the specific sound effect that is playing, will return -1 when muted or for background music.
- Throws:
InvalidSoundFileException
-
play
A convenience method to play a sound without explicitly controlling the loop property- Parameters:
sound
- An enum value that implements the SoundFile interface- Returns:
- a long integer corresponding to the specific sound effect that is playing, will return -1 for background music or -2 for an invalid sound file
- Throws:
InvalidSoundFileException
-
pause
Pause a SoundFile that is currently playing without losing the progress of that track. If the sound is not currently playing, then this method fails transparently without throwing errors (this will be logged on the debug channel).- Parameters:
sound
- - An enum value that implements the SoundFile interface- Throws:
InvalidSoundFileException
-
stop
Stop a SoundFile that is currently playing. You will lose the progress of the track. If the sound is not currently playing, then this method fails transparently without throwing errors (this will be logged on the debug channel).- Parameters:
sound
- - An enum value that implements the SoundFile interface- Throws:
InvalidSoundFileException
-
isMuted
boolean isMuted()Check if the current MusicService is currently muted.- Returns:
- The current mute state of the MusicService
-
setMuted
void setMuted(boolean muted) Mutes the playback of a given MusicService.- Parameters:
muted
- - The boolean state to set
-
isPlaying
Checks if a certain SoundFile is playing.- Parameters:
sound
- - An enum value that implements the SoundFile interface- Returns:
- The playback status of a given SoundFile
- Throws:
InvalidSoundFileException
-
loadSounds
Given a list of SoundFiles, load them all into memory.- Parameters:
sounds
- - A list of SoundFiles to be loaded into memory- Throws:
InvalidSoundFileException
-
dispose
void dispose()Dispose all the currently loaded SoundFiles from memory before closing the service. This may be moved to the deinit method of this class so that extra steps aren't needed otherwise.
-