Package pi.resources.sound
Class Playback
java.lang.Object
pi.resources.sound.Playback
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
MusicPlayback,SoundPlayback
The
SoundPlayback class is a wrapper SourceDataLine on which
a Sound playback can be carried out.- See Also:
-
play(Sound)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassAn object for controlling the volume of aSoundPlayback. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds aSoundPlaybackListenerto this instance.voidcancel()Attempts to cancel the playback of this audio.floatGets the current volume of this playback, considering allVolumeControlobjects created for it.floatGets the current master volume of this playback.booleanisPaused()Determines if this playback is paused.booleanDetermines if this playback has sound to play.voidPauses this playback.voidRemoves aSoundPlaybackListenerfrom this instance.voidResumes this playback.voidsetPaused(boolean paused) Sets the paused state of this playback to the provided value.voidsetVolume(float volume) Sets the master volume of this playback.voidstart()Starts playing the audio.
-
Field Details
-
line
-
-
Method Details
-
start
public void start()Starts playing the audio.- Throws:
IllegalStateException- if the audio has already been started
-
addSoundPlaybackListener
Adds aSoundPlaybackListenerto this instance.- Parameters:
listener- TheSoundPlaybackListenerto be added.
-
removeSoundPlaybackListener
Removes aSoundPlaybackListenerfrom this instance.- Parameters:
listener- TheSoundPlaybackListenerto be removed.
-
setPaused
public void setPaused(boolean paused) Sets the paused state of this playback to the provided value.- Parameters:
paused- Whether to pause or resume this playback
-
pausePlayback
public void pausePlayback()Pauses this playback. If this playback is already paused, this call has no effect. -
resumePlayback
public void resumePlayback()Resumes this playback. If this playback is already playing, this call has no effect. -
isPaused
public boolean isPaused()Determines if this playback is paused.- Returns:
- Whether this playback is paused
-
isPlaying
public boolean isPlaying()Determines if this playback has sound to play. If it is paused but still in the middle of playback, it will returntrue, but it will returnfalseif it has finished or it has been cancelled.- Returns:
- Whether this playback has sound to play
-
cancel
public void cancel()Attempts to cancel the playback of this audio. If the playback was successfully cancelled, it will notify listeners. -
getMasterVolume
public float getMasterVolume()Gets the current volume of this playback, considering allVolumeControlobjects created for it.- Returns:
- The current volume.
-
getVolume
public float getVolume()Gets the current master volume of this playback. This will be approximately equal to the value set by a previous call tosetVolume, though rounding errors may occur.- Returns:
- The settable volume.
-
setVolume
public void setVolume(float volume) Sets the master volume of this playback.- Parameters:
volume- The new volume.
-
createVolumeControl
-
getVolumeControls
-