Package de.gurkenlabs.litiengine.sound
Class SoundPlayback
java.lang.Object
de.gurkenlabs.litiengine.sound.SoundPlayback
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
MusicPlayback
,SFXPlayback
public abstract class SoundPlayback
extends java.lang.Object
implements java.lang.Runnable
The
SoundPlayback
class is a wrapper SourceDataLine
on which a Sound
playback can be carried out.- See Also:
play(Sound)
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SoundPlayback.VolumeControl
An object for controlling the volume of aSoundPlayback
.Field Summary
Fields Modifier and Type Field Description protected javax.sound.sampled.SourceDataLine
line
Method Summary
Modifier and Type Method Description void
addSoundPlaybackListener(SoundPlaybackListener listener)
Adds aSoundPlaybackListener
to this instance.void
cancel()
Attempts to cancel the playback of this audio.SoundPlayback.VolumeControl
createVolumeControl()
void
fade(int duration)
Fades this playback's volume to 0 over the given duration.void
fade(int duration, float target, TweenFunction easingType)
Fades this playback's volume to the target value over the given duration using the givenTweenFunction
.protected void
finalize()
Deprecated.float
getMasterVolume()
Gets the current volume of this playback, considering allVolumeControl
objects created for it.float
getVolume()
Gets the current master volume of this playback.java.util.Collection<SoundPlayback.VolumeControl>
getVolumeControls()
boolean
isPaused()
Determines if this playback is paused.boolean
isPlaying()
Determines if this playback has sound to play.void
pausePlayback()
Pauses this playback.void
removeSoundPlaybackListener(SoundPlaybackListener listener)
Removes aSoundPlaybackListener
from this instance.void
resumePlayback()
Resumes this playback.void
setPaused(boolean paused)
Sets the paused state of this playback to the provided value.void
setVolume(float volume)
Sets the master volume of this playback.void
start()
Starts playing the audio.
Field Details
line
protected final javax.sound.sampled.SourceDataLine line
Method Details
start
public void start()Starts playing the audio.- Throws:
java.lang.IllegalStateException
- if the audio has already been started
addSoundPlaybackListener
Adds aSoundPlaybackListener
to this instance.- Parameters:
listener
- TheSoundPlaybackListener
to be added.
removeSoundPlaybackListener
Removes aSoundPlaybackListener
from this instance.- Parameters:
listener
- TheSoundPlaybackListener
to 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.fade
public void fade(int duration)Fades this playback's volume to 0 over the given duration.- Parameters:
duration
- the fade duration in milliseconds.
fade
Fades this playback's volume to the target value over the given duration using the givenTweenFunction
.- Parameters:
duration
- the fade duration in milliseconds.target
- the target volume at the end of the fadeeasingType
- the TweenFunction determining the falloff curve of this fade.
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 returnfalse
if 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 allVolumeControl
objects 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
finalize
@Deprecated protected void finalize()Deprecated.- Overrides:
finalize
in classjava.lang.Object