Class EffectsMusicService

java.lang.Object
com.csse3200.game.services.sound.EffectsMusicService
All Implemented Interfaces:
MusicService

public class EffectsMusicService extends Object implements 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 Details

    • EffectsMusicService

      public EffectsMusicService()
  • Method Details

    • play

      public long play(SoundFile soundFile, boolean looping) throws InvalidSoundFileException
      Description copied from interface: MusicService
      Play a given SoundFile, with it optionally looping
      Specified by:
      play in interface MusicService
      Parameters:
      soundFile - - An enum value that implements the SoundFile interface
      looping - - 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

      public long play(SoundFile sound) throws InvalidSoundFileException
      Description copied from interface: MusicService
      A convenience method to play a sound without explicitly controlling the loop property
      Specified by:
      play in interface MusicService
      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

      public void pause(SoundFile sound) throws InvalidSoundFileException
      Functionally identical to the stop() method for the EffectsMusicService
      Specified by:
      pause in interface MusicService
      Parameters:
      sound - - An enum value that implements the SoundFile interface
      Throws:
      InvalidSoundFileException
    • stop

      public void stop(SoundFile soundFile) throws InvalidSoundFileException
      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 interface MusicService
      Parameters:
      soundFile - - An enum value that implements the SoundFile interface
      Throws:
      InvalidSoundFileException
    • stop

      public void stop(SoundFile soundFile, long id) throws InvalidSoundFileException
      Parameters:
      soundFile - The SoundFile to stop playing
      id - 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 interface MusicService
      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 interface MusicService
      Parameters:
      muted - - The boolean state to set
    • isPlaying

      public boolean isPlaying(SoundFile sound) throws InvalidSoundFileException
      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:
      isPlaying in interface MusicService
      Parameters:
      sound - - An enum value that implements the SoundFile interface
      Returns:
      The playback status of a given SoundFile
      Throws:
      InvalidSoundFileException
    • isPlaying

      public boolean isPlaying(SoundFile sound, long id) throws InvalidSoundFileException
      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 check
      id - The instance id of the sound
      Returns:
      Boolean status
      Throws:
      InvalidSoundFileException
    • loadSounds

      public void loadSounds(List<SoundFile> sounds) throws InvalidSoundFileException
      Description copied from interface: MusicService
      Given a list of SoundFiles, load them all into memory.
      Specified by:
      loadSounds in interface MusicService
      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 interface MusicService