Package com.csse3200.game.services.sound
Class EffectsMusicService
java.lang.Object
com.csse3200.game.services.sound.EffectsMusicService
- All Implemented Interfaces:
MusicService
A MusicService that handles playback for short (less than or equal to 5s) sound effects that are played from memory.
All files must be in the WAV format to ensure consistent playback.
There is no limit on the number of sound effects that can be loaded,
but loading too many will cause performance issues, so please be judicious.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose all the currently loaded SoundFiles from memory before closing the service.booleanisMuted()Check if the current MusicService is currently muted.booleanOnly tracks looping audio, as there is no method by which to check playing status of non-looping effects.booleanCheck if a certain instance of a SoundFile is playing.voidloadSounds(List<SoundFile> sounds) Given a list of SoundFiles, load them all into memory.voidFunctionally identical to thestop()method for the EffectsMusicServicelongA convenience method to play a sound without explicitly controlling the loop propertylongPlay a given SoundFile, with it optionally loopingvoidsetMuted(boolean muted) Mutes the playback of a given MusicService.voidStop a SoundFile that is currently playing.voidFunctionally similar tostop(1), but only stops a single instance of a Sound from playing
-
Constructor Details
-
EffectsMusicService
public EffectsMusicService()
-
-
Method Details
-
play
Description copied from interface:MusicServicePlay a given SoundFile, with it optionally looping- Specified by:
playin interfaceMusicService- Parameters:
soundFile- - 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
Description copied from interface:MusicServiceA convenience method to play a sound without explicitly controlling the loop property- Specified by:
playin interfaceMusicService- 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
Functionally identical to thestop()method for the EffectsMusicService- Specified by:
pausein interfaceMusicService- Parameters:
sound- - An enum value that implements the SoundFile interface- Throws:
InvalidSoundFileException
-
stop
Description copied from interface:MusicServiceStop 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).- Specified by:
stopin interfaceMusicService- Parameters:
soundFile- - An enum value that implements the SoundFile interface- Throws:
InvalidSoundFileException
-
stop
Functionally similar tostop(1), but only stops a single instance of a Sound from playing- Parameters:
soundFile- The SoundFile to stop playingid- The instance id of the sound to stop playing- Throws:
InvalidSoundFileException
-
setMuted
public void setMuted(boolean muted) Description copied from interface:MusicServiceMutes the playback of a given MusicService.- Specified by:
setMutedin interfaceMusicService- Parameters:
muted- - The boolean state to set
-
isMuted
public boolean isMuted()Description copied from interface:MusicServiceCheck if the current MusicService is currently muted.- Specified by:
isMutedin interfaceMusicService- Returns:
- The current mute state of the MusicService
-
isPlaying
Only tracks looping audio, as there is no method by which to check playing status of non-looping effects.
Checks if a certain SoundFile is playing.- Specified by:
isPlayingin interfaceMusicService- Parameters:
sound- - An enum value that implements the SoundFile interface- Returns:
- The playback status of a given SoundFile
- Throws:
InvalidSoundFileException
-
isPlaying
Check if a certain instance of a SoundFile is playing. Only tracks looping audio, as there is no method by which to check playing status of non-looping effects.- Parameters:
sound- The SoundFile to checkid- The instance id of the sound- Returns:
- Boolean status
- Throws:
InvalidSoundFileException
-
loadSounds
Description copied from interface:MusicServiceGiven a list of SoundFiles, load them all into memory.- Specified by:
loadSoundsin interfaceMusicService- Parameters:
sounds- - A list of SoundFiles to be loaded into memory- Throws:
InvalidSoundFileException
-
dispose
public void dispose()Description copied from interface:MusicServiceDispose 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.- Specified by:
disposein interfaceMusicService
-