Class LocalAudioTrackExecutor
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor
-
- All Implemented Interfaces:
AudioFrameProvider,AudioTrackExecutor
public class LocalAudioTrackExecutor extends java.lang.Object implements AudioTrackExecutor
Handles the execution and output buffering of an audio track.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLocalAudioTrackExecutor.ReadExecutorRead executor, see method descriptionstatic interfaceLocalAudioTrackExecutor.SeekExecutorSeek executor, see method description
-
Constructor Summary
Constructors Constructor Description LocalAudioTrackExecutor(InternalAudioTrack audioTrack, AudioConfiguration configuration, AudioPlayerOptions playerOptions, boolean useSeekGhosting, int bufferDuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMarker(TrackMarker marker)Adds a marker to the track.voidexecute(TrackStateListener listener)Execute the track, which means that this thread will fill the frame buffer until the track finishes or is stopped.voidexecuteProcessingLoop(LocalAudioTrackExecutor.ReadExecutor readExecutor, LocalAudioTrackExecutor.SeekExecutor seekExecutor)voidexecuteProcessingLoop(LocalAudioTrackExecutor.ReadExecutor readExecutor, LocalAudioTrackExecutor.SeekExecutor seekExecutor, boolean waitOnEnd)Execute the read and seek loop for the track.booleanfailedBeforeLoad()AudioFrameBuffergetAudioBuffer()longgetPosition()AudioProcessingContextgetProcessingContext()java.lang.StackTraceElement[]getStackTrace()AudioTrackStategetState()AudioFrameprovide()AudioFrameprovide(long timeout, java.util.concurrent.TimeUnit unit)booleanprovide(MutableAudioFrame targetFrame)booleanprovide(MutableAudioFrame targetFrame, long timeout, java.util.concurrent.TimeUnit unit)voidremoveMarker(TrackMarker marker)Removes a marker from the track.voidsetMarker(TrackMarker marker)Set the track position marker.voidsetPosition(long timecode)Perform seek to the specified timecode.voidstop()Stop playing the track, terminating the thread that is filling the frame buffer.voidwaitOnEnd()Wait until all the frames from the frame buffer have been consumed.
-
-
-
Constructor Detail
-
LocalAudioTrackExecutor
public LocalAudioTrackExecutor(InternalAudioTrack audioTrack, AudioConfiguration configuration, AudioPlayerOptions playerOptions, boolean useSeekGhosting, int bufferDuration)
- Parameters:
audioTrack- The audio track that this executor executesconfiguration- Configuration to use for audio processingplayerOptions- Mutable player options (for example volume).useSeekGhosting- Whether to keep providing old frames continuing from the previous position during a seek until frames from the new position arrive.bufferDuration- The size of the frame buffer in milliseconds
-
-
Method Detail
-
getProcessingContext
public AudioProcessingContext getProcessingContext()
-
getStackTrace
public java.lang.StackTraceElement[] getStackTrace()
-
getAudioBuffer
public AudioFrameBuffer getAudioBuffer()
- Specified by:
getAudioBufferin interfaceAudioTrackExecutor- Returns:
- The audio buffer of this executor.
-
execute
public void execute(TrackStateListener listener)
Description copied from interface:AudioTrackExecutorExecute the track, which means that this thread will fill the frame buffer until the track finishes or is stopped.- Specified by:
executein interfaceAudioTrackExecutor- Parameters:
listener- Listener for track state events
-
stop
public void stop()
Description copied from interface:AudioTrackExecutorStop playing the track, terminating the thread that is filling the frame buffer. Subsequent playback requires a new executor.- Specified by:
stopin interfaceAudioTrackExecutor
-
waitOnEnd
public void waitOnEnd() throws java.lang.InterruptedExceptionWait until all the frames from the frame buffer have been consumed. Keeps the buffering thread alive to keep it interruptible for seeking until buffer is empty.- Throws:
java.lang.InterruptedException- When interrupted externally (or for seek/stop).
-
getPosition
public long getPosition()
- Specified by:
getPositionin interfaceAudioTrackExecutor- Returns:
- Timecode of the last played frame or in case a seek is in progress, the timecode of the frame being seeked to.
-
setPosition
public void setPosition(long timecode)
Description copied from interface:AudioTrackExecutorPerform seek to the specified timecode.- Specified by:
setPositionin interfaceAudioTrackExecutor- Parameters:
timecode- The timecode in milliseconds
-
getState
public AudioTrackState getState()
- Specified by:
getStatein interfaceAudioTrackExecutor- Returns:
- Current state of the executor
-
setMarker
public void setMarker(TrackMarker marker)
Description copied from interface:AudioTrackExecutorSet the track position marker. This will clear all existing markers.- Specified by:
setMarkerin interfaceAudioTrackExecutor- Parameters:
marker- Track position marker to set.
-
addMarker
public void addMarker(TrackMarker marker)
Description copied from interface:AudioTrackExecutorAdds a marker to the track. Markers can be used to execute code when the track reaches a certain position.- Specified by:
addMarkerin interfaceAudioTrackExecutor- Parameters:
marker- The marker to add.
-
removeMarker
public void removeMarker(TrackMarker marker)
Description copied from interface:AudioTrackExecutorRemoves a marker from the track.- Specified by:
removeMarkerin interfaceAudioTrackExecutor- Parameters:
marker- The marker to remove.
-
failedBeforeLoad
public boolean failedBeforeLoad()
- Specified by:
failedBeforeLoadin interfaceAudioTrackExecutor- Returns:
- True if this track threw an exception before it provided any audio.
-
executeProcessingLoop
public void executeProcessingLoop(LocalAudioTrackExecutor.ReadExecutor readExecutor, LocalAudioTrackExecutor.SeekExecutor seekExecutor)
-
executeProcessingLoop
public void executeProcessingLoop(LocalAudioTrackExecutor.ReadExecutor readExecutor, LocalAudioTrackExecutor.SeekExecutor seekExecutor, boolean waitOnEnd)
Execute the read and seek loop for the track.- Parameters:
readExecutor- Callback for reading the trackseekExecutor- Callback for performing a seek on the track, may be null on a non-seekable track
-
provide
public AudioFrame provide()
- Specified by:
providein interfaceAudioFrameProvider- Returns:
- Provided frame, or null if none available
-
provide
public AudioFrame provide(long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
- Specified by:
providein interfaceAudioFrameProvider- Parameters:
timeout- Specifies the maximum time to wait for data. Pass 0 for non-blocking mode.unit- Specifies the time unit of the maximum wait time.- Returns:
- Provided frame. In case wait time is above zero, null indicates that no data is not available at the current moment, otherwise null means the end of the track.
- Throws:
java.util.concurrent.TimeoutException- When wait time is above zero, but no track info is found in that time.java.lang.InterruptedException- When interrupted externally (or for seek/stop).
-
provide
public boolean provide(MutableAudioFrame targetFrame)
- Specified by:
providein interfaceAudioFrameProvider- Parameters:
targetFrame- Frame to update with the details and data of the provided frame.- Returns:
trueif a frame was provided.
-
provide
public boolean provide(MutableAudioFrame targetFrame, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException
- Specified by:
providein interfaceAudioFrameProvider- Parameters:
targetFrame- Frame to update with the details and data of the provided frame.timeout- Timeout.unit- Time unit for the timeout value.- Returns:
trueif a frame was provided.- Throws:
java.util.concurrent.TimeoutException- If no frame became available within the timeout.java.lang.InterruptedException- When interrupted externally (or for seek/stop).
-
-