Class BaseAudioTrack
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.track.BaseAudioTrack
-
- All Implemented Interfaces:
AudioItem,AudioTrack,InternalAudioTrack,AudioFrameProvider
- Direct Known Subclasses:
AdtsAudioTrack,DelegatedAudioTrack,FlacAudioTrack,MatroskaAudioTrack,Mp3AudioTrack,MpegAudioTrack,OggAudioTrack,WavAudioTrack
public abstract class BaseAudioTrack extends java.lang.Object implements InternalAudioTrack
Abstract base for all audio tracks with an executor
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicLongaccurateDurationprotected AudioTrackInfotrackInfo
-
Constructor Summary
Constructors Constructor Description BaseAudioTrack(AudioTrackInfo trackInfo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMarker(TrackMarker marker)Adds a marker to the track.voidassignExecutor(AudioTrackExecutor executor, boolean applyPrimordialState)AudioTrackExecutorcreateLocalExecutor(AudioPlayerManager playerManager)AudioTrackExecutorgetActiveExecutor()longgetDuration()java.lang.StringgetIdentifier()AudioTrackInfogetInfo()longgetPosition()AudioSourceManagergetSourceManager()AudioTrackStategetState()java.lang.ObjectgetUserData()<T> TgetUserData(java.lang.Class<T> klass)booleanisSeekable()AudioTrackmakeClone()protected AudioTrackmakeShallowClone()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 position)Seek to the specified position.voidsetUserData(java.lang.Object userData)Attach an object with this track which can later be retrieved withAudioTrack.getUserData().voidstop()Stop the track if it is currently playing-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack
process
-
-
-
-
Field Detail
-
trackInfo
protected final AudioTrackInfo trackInfo
-
accurateDuration
protected final java.util.concurrent.atomic.AtomicLong accurateDuration
-
-
Constructor Detail
-
BaseAudioTrack
public BaseAudioTrack(AudioTrackInfo trackInfo)
- Parameters:
trackInfo- Track info
-
-
Method Detail
-
assignExecutor
public void assignExecutor(AudioTrackExecutor executor, boolean applyPrimordialState)
- Specified by:
assignExecutorin interfaceInternalAudioTrack- Parameters:
executor- Executor to assign to the trackapplyPrimordialState- True if the state previously applied to this track should be copied to new executor.
-
getActiveExecutor
public AudioTrackExecutor getActiveExecutor()
- Specified by:
getActiveExecutorin interfaceInternalAudioTrack- Returns:
- Get the active track executor
-
stop
public void stop()
Description copied from interface:AudioTrackStop the track if it is currently playing- Specified by:
stopin interfaceAudioTrack
-
getState
public AudioTrackState getState()
- Specified by:
getStatein interfaceAudioTrack- Returns:
- The current execution state of the track
-
getIdentifier
public java.lang.String getIdentifier()
- Specified by:
getIdentifierin interfaceAudioTrack- Returns:
- The identifier of the track
-
isSeekable
public boolean isSeekable()
- Specified by:
isSeekablein interfaceAudioTrack- Returns:
- True if the track is seekable.
-
getPosition
public long getPosition()
- Specified by:
getPositionin interfaceAudioTrack- Returns:
- Get the current position of the track in milliseconds
-
setPosition
public void setPosition(long position)
Description copied from interface:AudioTrackSeek to the specified position.- Specified by:
setPositionin interfaceAudioTrack- Parameters:
position- New position of the track in milliseconds
-
setMarker
public void setMarker(TrackMarker marker)
Description copied from interface:AudioTrackSet the track position marker. This will clear all existing markers.- Specified by:
setMarkerin interfaceAudioTrack- Parameters:
marker- Track position marker to place
-
addMarker
public void addMarker(TrackMarker marker)
Description copied from interface:AudioTrackAdds a marker to the track. Markers can be used to execute code when the track reaches a certain position.- Specified by:
addMarkerin interfaceAudioTrack- Parameters:
marker- The marker to add.
-
removeMarker
public void removeMarker(TrackMarker marker)
Description copied from interface:AudioTrackRemoves a marker from the track.- Specified by:
removeMarkerin interfaceAudioTrack- Parameters:
marker- The marker to remove.
-
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).
-
getInfo
public AudioTrackInfo getInfo()
- Specified by:
getInfoin interfaceAudioTrack- Returns:
- Track meta information
-
getDuration
public long getDuration()
- Specified by:
getDurationin interfaceAudioTrack- Returns:
- Duration of the track in milliseconds
-
makeClone
public AudioTrack makeClone()
- Specified by:
makeClonein interfaceAudioTrack- Returns:
- Clone of this track which does not share the execution state of this track
-
getSourceManager
public AudioSourceManager getSourceManager()
- Specified by:
getSourceManagerin interfaceAudioTrack- Returns:
- The source manager which created this track. Null if not created by a source manager directly.
-
createLocalExecutor
public AudioTrackExecutor createLocalExecutor(AudioPlayerManager playerManager)
- Specified by:
createLocalExecutorin interfaceInternalAudioTrack- Parameters:
playerManager- The player manager which is executing this track- Returns:
- A custom local executor for this track. Unless this track requires a special executor, this should return null as the default one will be used in that case.
-
setUserData
public void setUserData(java.lang.Object userData)
Description copied from interface:AudioTrackAttach an object with this track which can later be retrieved withAudioTrack.getUserData(). Useful for retrieving application-specific object from the track in callbacks.- Specified by:
setUserDatain interfaceAudioTrack- Parameters:
userData- Object to store.
-
getUserData
public java.lang.Object getUserData()
- Specified by:
getUserDatain interfaceAudioTrack- Returns:
- Object previously stored with
AudioTrack.setUserData(Object)
-
getUserData
public <T> T getUserData(java.lang.Class<T> klass)
- Specified by:
getUserDatain interfaceAudioTrack- Parameters:
klass- The expected class of the user data (or a superclass of it).- Returns:
- Object previously stored with
AudioTrack.setUserData(Object)if it is of the specified type. If it is set, but with a different type, null is returned.
-
makeShallowClone
protected AudioTrack makeShallowClone()
-
-