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 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
Only tracks looping audio, as there is no method by which to check playing status of non-looping effects.boolean
Check if a certain instance of a SoundFile is playing.void
loadSounds
(List<SoundFile> sounds) Given a list of SoundFiles, load them all into memory.void
Functionally identical to thestop()
method for the EffectsMusicServicelong
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.void
Functionally 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:MusicService
Play a given SoundFile, with it optionally looping- Specified by:
play
in 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:MusicService
A convenience method to play a sound without explicitly controlling the loop property- Specified by:
play
in 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:
pause
in interfaceMusicService
- Parameters:
sound
- - An enum value that implements the SoundFile interface- Throws:
InvalidSoundFileException
-
stop
Description copied from interface:MusicService
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).- Specified by:
stop
in 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
-
isMuted
public boolean isMuted()Description copied from interface:MusicService
Check if the current MusicService is currently muted.- Specified by:
isMuted
in interfaceMusicService
- Returns:
- The current mute state of the MusicService
-
setMuted
public void setMuted(boolean muted) Description copied from interface:MusicService
Mutes the playback of a given MusicService.- Specified by:
setMuted
in interfaceMusicService
- Parameters:
muted
- - The boolean state to set
-
isPlaying
Only tracks looping audio, as there is no method by which to check playing status of non-looping effects.- Specified by:
isPlaying
in 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:MusicService
Given a list of SoundFiles, load them all into memory.- Specified by:
loadSounds
in interfaceMusicService
- Parameters:
sounds
- - A list of SoundFiles to be loaded into memory- Throws:
InvalidSoundFileException
-
dispose
public void dispose()Description copied from interface:MusicService
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.- Specified by:
dispose
in interfaceMusicService
-