Class DefaultAudioPlayerManager
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager
-
- All Implemented Interfaces:
AudioPlayerManager
public class DefaultAudioPlayerManager extends java.lang.Object implements AudioPlayerManager
The default implementation of audio player manager.
-
-
Constructor Summary
Constructors Constructor Description DefaultAudioPlayerManager()Create a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AudioPlayerconstructPlayer()AudioPlayercreatePlayer()DecodedTrackHolderdecodeTrack(MessageInput stream)Decode a track from an input stream.AudioTrackdecodeTrackDetails(AudioTrackInfo trackInfo, byte[] buffer)Decodes an audio track from a byte array.voidenableGcMonitoring()Enable reporting GC pause length statistics to log (warn level with lengths bad for latency, debug level otherwise)voidencodeTrack(MessageOutput stream, AudioTrack track)Encode a track into an output stream.byte[]encodeTrackDetails(AudioTrack track)Encodes an audio track to a byte array.voidexecuteTrack(TrackStateListener listener, InternalAudioTrack track, AudioConfiguration configuration, AudioPlayerOptions playerOptions)Executes an audio track with the given player and volume.AudioConfigurationgetConfiguration()java.util.concurrent.ExecutorServicegetExecutor()intgetFrameBufferDuration()java.util.List<AudioSourceManager>getSourceManagers()longgetTrackStuckThresholdNanos()booleanisUsingSeekGhosting()Seek ghosting is the effect where while a seek is in progress, buffered audio from the previous location will be served until seek is ready or the buffer is empty.java.util.concurrent.Future<java.lang.Void>loadItem(AudioReference reference, AudioLoadResultHandler resultHandler)Schedules loading a track or playlist with the specified identifier.java.util.concurrent.Future<java.lang.Void>loadItemOrdered(java.lang.Object orderingKey, AudioReference reference, AudioLoadResultHandler resultHandler)Schedules loading a track or playlist with the specified identifier with an ordering key so that items with the same ordering key are handled sequentially in the order of calls to this method.@Nullable AudioItemloadItemSync(AudioReference reference)Loads a track or playlist with the specified identifier and returns it.voidloadItemSync(AudioReference reference, AudioLoadResultHandler resultHandler)Loads a track or playlist with the specified identifier.voidregisterSourceManager(AudioSourceManager sourceManager)voidsetFrameBufferDuration(int frameBufferDuration)voidsetHttpBuilderConfigurator(java.util.function.Consumer<org.apache.http.impl.client.HttpClientBuilder> configurator)voidsetHttpRequestConfigurator(java.util.function.Function<org.apache.http.client.config.RequestConfig,org.apache.http.client.config.RequestConfig> configurator)voidsetItemLoaderThreadPoolSize(int poolSize)Sets the number of threads used for loading processing item load requests.voidsetPlayerCleanupThreshold(long cleanupThreshold)Sets the threshold for clearing an audio player when it has not been queried for the specified amount of time.voidsetTrackStuckThreshold(long trackStuckThreshold)Sets the threshold for how long a track can be stuck until the TrackStuckEvent is sent out.voidsetUseSeekGhosting(boolean useSeekGhosting)voidshutdown()Shut down the manager.<T extends AudioSourceManager>
Tsource(java.lang.Class<T> klass)Shortcut for accessing a source manager of a certain class.-
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.player.AudioPlayerManager
loadItem, loadItemOrdered, loadItemSync, loadItemSync, registerSourceManagers
-
-
-
-
Method Detail
-
shutdown
public void shutdown()
Description copied from interface:AudioPlayerManagerShut down the manager. All threads will be stopped, the manager cannot be used any further. All players created with this manager will stop and all source managers registered to this manager will also be shut down.Every thread created by the audio manager is a daemon thread, so calling this is not required for an application to be able to gracefully shut down, however it should be called if the application continues without requiring this manager any longer.
- Specified by:
shutdownin interfaceAudioPlayerManager
-
enableGcMonitoring
public void enableGcMonitoring()
Description copied from interface:AudioPlayerManagerEnable reporting GC pause length statistics to log (warn level with lengths bad for latency, debug level otherwise)- Specified by:
enableGcMonitoringin interfaceAudioPlayerManager
-
registerSourceManager
public void registerSourceManager(AudioSourceManager sourceManager)
- Specified by:
registerSourceManagerin interfaceAudioPlayerManager- Parameters:
sourceManager- The source manager to register, which will be used for subsequent loadItem calls
-
source
public <T extends AudioSourceManager> T source(java.lang.Class<T> klass)
Description copied from interface:AudioPlayerManagerShortcut for accessing a source manager of a certain class.- Specified by:
sourcein interfaceAudioPlayerManager- Type Parameters:
T- The class of the source manager.- Parameters:
klass- The class of the source manager to return.- Returns:
- The source manager of the specified class, or null if not registered.
-
getSourceManagers
public java.util.List<AudioSourceManager> getSourceManagers()
- Specified by:
getSourceManagersin interfaceAudioPlayerManager- Returns:
- A list of all registered audio source managers.
-
loadItemSync
@Nullable public @Nullable AudioItem loadItemSync(AudioReference reference)
Description copied from interface:AudioPlayerManagerLoads a track or playlist with the specified identifier and returns it.- Specified by:
loadItemSyncin interfaceAudioPlayerManager- Parameters:
reference- The audio reference that holds the identifier that a specific source manager should be able to find the track with.- Returns:
- The loaded
AudioItem, or `null` if nothing was found.
-
loadItemSync
public void loadItemSync(AudioReference reference, AudioLoadResultHandler resultHandler)
Description copied from interface:AudioPlayerManagerLoads a track or playlist with the specified identifier.- Specified by:
loadItemSyncin interfaceAudioPlayerManager- Parameters:
reference- The audio reference that holds the identifier that a specific source manager should be able to find the track with.resultHandler- A handler to process the result of this operation. It can either end by finding a track, finding a playlist, finding nothing or terminating with an exception.- See Also:
AudioPlayerManager.loadItemSync(String, AudioLoadResultHandler)
-
loadItem
public java.util.concurrent.Future<java.lang.Void> loadItem(AudioReference reference, AudioLoadResultHandler resultHandler)
Description copied from interface:AudioPlayerManagerSchedules loading a track or playlist with the specified identifier.- Specified by:
loadItemin interfaceAudioPlayerManager- Parameters:
reference- The audio reference that holds the identifier that a specific source manager should be able to find the track with.resultHandler- A handler to process the result of this operation. It can either end by finding a track, finding a playlist, finding nothing or terminating with an exception.- Returns:
- A future for this operation
- See Also:
AudioPlayerManager.loadItem(String, AudioLoadResultHandler)
-
loadItemOrdered
public java.util.concurrent.Future<java.lang.Void> loadItemOrdered(java.lang.Object orderingKey, AudioReference reference, AudioLoadResultHandler resultHandler)Description copied from interface:AudioPlayerManagerSchedules loading a track or playlist with the specified identifier with an ordering key so that items with the same ordering key are handled sequentially in the order of calls to this method.- Specified by:
loadItemOrderedin interfaceAudioPlayerManager- Parameters:
orderingKey- Object to use as the key for the ordering channelreference- The audio reference that holds the identifier that a specific source manager should be able to find the track with.resultHandler- A handler to process the result of this operation. It can either end by finding a track, finding a playlist, finding nothing or terminating with an exception.- Returns:
- A future for this operation
- See Also:
AudioPlayerManager.loadItemOrdered(Object, String, AudioLoadResultHandler)
-
encodeTrack
public void encodeTrack(MessageOutput stream, AudioTrack track) throws java.io.IOException
Description copied from interface:AudioPlayerManagerEncode a track into an output stream. If the decoder is not supposed to know the number of tracks in advance, then the encoder should call MessageOutput#finish() after all the tracks it wanted to write have been written. This will make decodeTrack() return null at that position- Specified by:
encodeTrackin interfaceAudioPlayerManager- Parameters:
stream- The message stream to write it to.track- The track to encode.- Throws:
java.io.IOException- On IO error.
-
decodeTrack
public DecodedTrackHolder decodeTrack(MessageInput stream) throws java.io.IOException
Description copied from interface:AudioPlayerManagerDecode a track from an input stream. Null returns value indicates reaching the position where the decoder had called MessageOutput#finish().- Specified by:
decodeTrackin interfaceAudioPlayerManager- Parameters:
stream- The message stream to read it from.- Returns:
- Holder containing the track if it was successfully decoded.
- Throws:
java.io.IOException- On IO error.
-
encodeTrackDetails
public byte[] encodeTrackDetails(AudioTrack track)
Encodes an audio track to a byte array. Does not include AudioTrackInfo in the buffer.- Parameters:
track- The track to encode- Returns:
- The bytes of the encoded data
-
decodeTrackDetails
public AudioTrack decodeTrackDetails(AudioTrackInfo trackInfo, byte[] buffer)
Decodes an audio track from a byte array.- Parameters:
trackInfo- Track info for the track to decodebuffer- Byte array containing the encoded track- Returns:
- Decoded audio track
-
executeTrack
public void executeTrack(TrackStateListener listener, InternalAudioTrack track, AudioConfiguration configuration, AudioPlayerOptions playerOptions)
Executes an audio track with the given player and volume.- Parameters:
listener- A listener for track state eventstrack- The audio track to executeconfiguration- The audio configuration to use for executingplayerOptions- Options of the audio player
-
getConfiguration
public AudioConfiguration getConfiguration()
- Specified by:
getConfigurationin interfaceAudioPlayerManager- Returns:
- Audio processing configuration used for tracks executed by this manager.
-
isUsingSeekGhosting
public boolean isUsingSeekGhosting()
Description copied from interface:AudioPlayerManagerSeek ghosting is the effect where while a seek is in progress, buffered audio from the previous location will be served until seek is ready or the buffer is empty.- Specified by:
isUsingSeekGhostingin interfaceAudioPlayerManager- Returns:
- True if seek ghosting is enabled.
-
setUseSeekGhosting
public void setUseSeekGhosting(boolean useSeekGhosting)
- Specified by:
setUseSeekGhostingin interfaceAudioPlayerManager- Parameters:
useSeekGhosting- The new state of seek ghosting
-
getFrameBufferDuration
public int getFrameBufferDuration()
- Specified by:
getFrameBufferDurationin interfaceAudioPlayerManager- Returns:
- The length of the internal buffer for audio in milliseconds.
-
setFrameBufferDuration
public void setFrameBufferDuration(int frameBufferDuration)
- Specified by:
setFrameBufferDurationin interfaceAudioPlayerManager- Parameters:
frameBufferDuration- New length of the internal buffer for audio in milliseconds.
-
setTrackStuckThreshold
public void setTrackStuckThreshold(long trackStuckThreshold)
Description copied from interface:AudioPlayerManagerSets the threshold for how long a track can be stuck until the TrackStuckEvent is sent out. A track is considered to be stuck if the player receives requests for audio samples from the track, but the audio frame provider of that track has been returning no data for the specified time.- Specified by:
setTrackStuckThresholdin interfaceAudioPlayerManager- Parameters:
trackStuckThreshold- The threshold in milliseconds.
-
getTrackStuckThresholdNanos
public long getTrackStuckThresholdNanos()
-
setPlayerCleanupThreshold
public void setPlayerCleanupThreshold(long cleanupThreshold)
Description copied from interface:AudioPlayerManagerSets the threshold for clearing an audio player when it has not been queried for the specified amount of time.- Specified by:
setPlayerCleanupThresholdin interfaceAudioPlayerManager- Parameters:
cleanupThreshold- The threshold in milliseconds.
-
setItemLoaderThreadPoolSize
public void setItemLoaderThreadPoolSize(int poolSize)
Description copied from interface:AudioPlayerManagerSets the number of threads used for loading processing item load requests.- Specified by:
setItemLoaderThreadPoolSizein interfaceAudioPlayerManager- Parameters:
poolSize- Maximum number of concurrent threads used for loading items.
-
getExecutor
public java.util.concurrent.ExecutorService getExecutor()
-
createPlayer
public AudioPlayer createPlayer()
- Specified by:
createPlayerin interfaceAudioPlayerManager- Returns:
- New audio player.
-
constructPlayer
protected AudioPlayer constructPlayer()
-
setHttpRequestConfigurator
public void setHttpRequestConfigurator(java.util.function.Function<org.apache.http.client.config.RequestConfig,org.apache.http.client.config.RequestConfig> configurator)
- Specified by:
setHttpRequestConfiguratorin interfaceAudioPlayerManager- Parameters:
configurator- Function used to reconfigure the request config of all sources which perform HTTP requests. Applied to all current and future registered sources. Setting this while sources are already in use will close all active connections, so this should be called before the sources have been used.
-
setHttpBuilderConfigurator
public void setHttpBuilderConfigurator(java.util.function.Consumer<org.apache.http.impl.client.HttpClientBuilder> configurator)
- Specified by:
setHttpBuilderConfiguratorin interfaceAudioPlayerManager- Parameters:
configurator- Function used to reconfigure the HTTP builder of all sources which perform HTTP requests. Applied to all current and future registered sources. Setting this while sources are already in use will close all active connections, so this should be called before the sources have been used.
-
-