Package ca.corbett.extras.audio
Class PlaybackThread
java.lang.Object
ca.corbett.extras.audio.PlaybackThread
- All Implemented Interfaces:
Runnable
Provides a worker thread that can be used to play audio clips. You can instantiate
this directly, but it's easier to go through the various play() wrapper functions
in AudioUtil to generate and start the thread for you.
- Since:
- 2018-01-10
- Author:
- scorbo2
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Clipprotected booleanprotected longprotected final longprotected final List<PlaybackListener> protected final longprotected PlaybackThread.StopReasonprotected static int -
Constructor Summary
ConstructorsConstructorDescriptionPlaybackThread(AudioInputStream audioStream, long offset, long limit, PlaybackListener listener) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPlaybackListener(PlaybackListener listener) protected booleanfireProgressEvent(long current, long total) protected voidprotected voidfireStopEvent(PlaybackThread.StopReason stopReason) longReturns the current offset, in milliseconds, of the playback.static intbooleanvoidremovePlaybackListener(PlaybackListener listener) voidrun()static voidsetUpdateIntervalMs(int ms) voidstop()
-
Field Details
-
UPDATE_MS
protected static int UPDATE_MS -
clip
-
isPlaying
protected volatile boolean isPlaying -
offsetms
protected final long offsetms -
limitms
protected final long limitms -
lastPlayPositionms
protected long lastPlayPositionms -
listeners
-
stopReason
-
-
Constructor Details
-
PlaybackThread
public PlaybackThread(AudioInputStream audioStream, long offset, long limit, PlaybackListener listener) throws LineUnavailableException, IOException - Throws:
LineUnavailableExceptionIOException
-
-
Method Details
-
isPlaying
public boolean isPlaying() -
stop
public void stop() -
getCurrentOffset
public long getCurrentOffset()Returns the current offset, in milliseconds, of the playback. If the playback is stopped, this value will represent the last playback position.- Returns:
- The current offset, in ms, of the playback.
-
getUpdateIntervalMs
public static int getUpdateIntervalMs() -
setUpdateIntervalMs
public static void setUpdateIntervalMs(int ms) -
run
public void run() -
addPlaybackListener
-
removePlaybackListener
-
fireStartedEvent
protected void fireStartedEvent() -
fireProgressEvent
protected boolean fireProgressEvent(long current, long total) -
fireStopEvent
-