Package doodlepad

Class Sound

java.lang.Object
doodlepad.Sound
All Implemented Interfaces:
EventListener, LineListener

public class Sound extends Object implements LineListener
A class that loads a supported sound file and allows it to be played. Multiple sound file formats are supported, including WAV.
  • Constructor Details

    • Sound

      public Sound()
      Nullary Sound constructor not initialized with sound file
    • Sound

      public Sound(String path)
      Sound constructor initiated with a sound file
      Parameters:
      path - Full path to a sound file
  • Method Details

    • open

      Open an audio file and create a sound clip ready to be played
      Parameters:
      path - Full path to a sound file
      Throws:
      IOException - when a problem occurs while opening sound file
      FileNotFoundException - when sound file path does not exist
      UnsupportedAudioFileException - when a sound file of unknown format is attempted to be opened
      LineUnavailableException - when the sound is not able to be played
    • close

      public void close()
      Close a sound file
    • isOpen

      public boolean isOpen()
      Check if a sound file is open
      Returns:
      A boolean indicating if a sound file is open
    • getPath

      public String getPath()
      Get the path to the Sound file
      Returns:
      Sound file path
    • getClip

      public Clip getClip()
      Get the internal managed javax.sound.sampled.Clip object
      Returns:
      Clip object
    • play

      public void play()
      Play a sound clip of the clip has been loaded and opened
    • stop

      public void stop()
      Stop a sound if currently being played
    • setEventsEnabled

      public void setEventsEnabled(boolean enabled)
      Enable or disable add Pad events.
      Parameters:
      enabled - True to enable. False to disable
    • setSoundOpenedHandler

      public void setSoundOpenedHandler(Sound.SoundEventHandler handler)
      Assign an onSoundOpened event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setSoundClosedHandler

      public void setSoundClosedHandler(Sound.SoundEventHandler handler)
      Assign an onSoundClosed event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setSoundStartedHandler

      public void setSoundStartedHandler(Sound.SoundEventHandler handler)
      Assign an onSoundStarted event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setSoundStoppedHandler

      public void setSoundStoppedHandler(Sound.SoundEventHandler handler)
      Assign an onSoundStopped event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • onSoundOpened

      public void onSoundOpened()
      A method that can be overridden to handle Sound opened events
    • onSoundClosed

      public void onSoundClosed()
      A method that can be overridden to handle Sound closed events
    • onSoundStarted

      public void onSoundStarted()
      A method that can be overridden to handle Sound started events
    • onSoundStopped

      public void onSoundStopped()
      A method that can be overridden to handle Sound stopped events
    • update

      public void update(LineEvent ev)
      Dispatch Line events
      Specified by:
      update in interface LineListener