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
Modifier and TypeClassDescriptionstatic interface
Interface used by methods that assign Sound event handlers given a method reference as a parameter. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close a sound filegetClip()
Get the internal managed javax.sound.sampled.Clip objectgetPath()
Get the path to the Sound fileboolean
isOpen()
Check if a sound file is openvoid
A method that can be overridden to handle Sound closed eventsvoid
A method that can be overridden to handle Sound opened eventsvoid
A method that can be overridden to handle Sound started eventsvoid
A method that can be overridden to handle Sound stopped eventsvoid
Open an audio file and create a sound clip ready to be playedvoid
play()
Play a sound clip of the clip has been loaded and openedvoid
setEventsEnabled
(boolean enabled) Enable or disable add Pad events.void
Assign an onSoundClosed event handler using a method reference.void
Assign an onSoundOpened event handler using a method reference.void
Assign an onSoundStarted event handler using a method reference.void
Assign an onSoundStopped event handler using a method reference.void
stop()
Stop a sound if currently being playedvoid
Dispatch 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:
update
in interfaceLineListener
-