Package doodlepad
Class Sound
java.lang.Object
doodlepad.Sound
- All Implemented Interfaces:
EventListener,LineListener
A class that loads a supported sound file and allows it to be played.
Multiple sound file formats are supported, including WAV.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface used by methods that assign Sound event handlers given a method reference as a parameter. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close a sound filegetClip()Get the internal managed javax.sound.sampled.Clip objectgetPath()Get the path to the Sound filebooleanisOpen()Check if a sound file is openvoidA method that can be overridden to handle Sound closed eventsvoidA method that can be overridden to handle Sound opened eventsvoidA method that can be overridden to handle Sound started eventsvoidA method that can be overridden to handle Sound stopped eventsvoidOpen an audio file and create a sound clip ready to be playedvoidplay()Play a sound clip of the clip has been loaded and openedvoidsetEventsEnabled(boolean enabled) Enable or disable add Pad events.voidAssign an onSoundClosed event handler using a method reference.voidAssign an onSoundOpened event handler using a method reference.voidAssign an onSoundStarted event handler using a method reference.voidAssign an onSoundStopped event handler using a method reference.voidstop()Stop a sound if currently being playedvoidDispatch Line events
-
Constructor Details
-
Sound
public Sound()Nullary Sound constructor not initialized with sound file -
Sound
Sound constructor initiated with a sound file- Parameters:
path- Full path to a sound file
-
-
Method Details
-
open
public void open(String path) throws IOException, FileNotFoundException, UnsupportedAudioFileException, LineUnavailableException 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 fileFileNotFoundException- when sound file path does not existUnsupportedAudioFileException- when a sound file of unknown format is attempted to be openedLineUnavailableException- 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
Get the path to the Sound file- Returns:
- Sound file path
-
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
Assign an onSoundOpened event handler using a method reference.- Parameters:
handler- Method reference to an event handler
-
setSoundClosedHandler
Assign an onSoundClosed event handler using a method reference.- Parameters:
handler- Method reference to an event handler
-
setSoundStartedHandler
Assign an onSoundStarted event handler using a method reference.- Parameters:
handler- Method reference to an event handler
-
setSoundStoppedHandler
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
Dispatch Line events- Specified by:
updatein interfaceLineListener
-