Interface AudioPlayerManager
-
- All Known Implementing Classes:
DefaultAudioPlayerManager
public interface AudioPlayerManagerAudio player manager which is used for creating audio players and loading tracks and playlists.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description AudioPlayercreatePlayer()DecodedTrackHolderdecodeTrack(MessageInput stream)Decode a track from an input stream.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.AudioConfigurationgetConfiguration()intgetFrameBufferDuration()java.util.List<AudioSourceManager>getSourceManagers()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.default java.util.concurrent.Future<java.lang.Void>loadItem(java.lang.String identifier, 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.default java.util.concurrent.Future<java.lang.Void>loadItemOrdered(java.lang.Object orderingKey, java.lang.String identifier, 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.default @Nullable AudioItemloadItemSync(java.lang.String reference)Loads a track or playlist with the specified identifier and returns it.default voidloadItemSync(java.lang.String identifier, AudioLoadResultHandler resultHandler)Loads a track or playlist with the specified identifier.voidregisterSourceManager(AudioSourceManager sourceManager)default voidregisterSourceManagers(AudioSourceManager... sourceManagers)Same asregisterSourceManager(AudioSourceManager)but registers multiple in one call.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.
-
-
-
Method Detail
-
shutdown
void shutdown()
Shut 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.
-
enableGcMonitoring
void enableGcMonitoring()
Enable reporting GC pause length statistics to log (warn level with lengths bad for latency, debug level otherwise)
-
registerSourceManager
void registerSourceManager(AudioSourceManager sourceManager)
- Parameters:
sourceManager- The source manager to register, which will be used for subsequent loadItem calls
-
registerSourceManagers
default void registerSourceManagers(AudioSourceManager... sourceManagers)
Same asregisterSourceManager(AudioSourceManager)but registers multiple in one call.- Parameters:
sourceManagers- The source managers to register, which will be used for subsequent loadItem calls
-
source
<T extends AudioSourceManager> T source(java.lang.Class<T> klass)
Shortcut for accessing a source manager of a certain class.- 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
java.util.List<AudioSourceManager> getSourceManagers()
- Returns:
- A list of all registered audio source managers.
-
loadItem
default java.util.concurrent.Future<java.lang.Void> loadItem(java.lang.String identifier, AudioLoadResultHandler resultHandler)Schedules loading a track or playlist with the specified identifier.- Parameters:
identifier- 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:
loadItem(AudioReference, AudioLoadResultHandler)
-
loadItem
java.util.concurrent.Future<java.lang.Void> loadItem(AudioReference reference, AudioLoadResultHandler resultHandler)
Schedules loading a track or playlist with the specified identifier.- 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:
loadItem(String, AudioLoadResultHandler)
-
loadItemSync
default void loadItemSync(java.lang.String identifier, AudioLoadResultHandler resultHandler)Loads a track or playlist with the specified identifier.- Parameters:
identifier- 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:
loadItemSync(AudioReference, AudioLoadResultHandler)
-
loadItemSync
void loadItemSync(AudioReference reference, AudioLoadResultHandler resultHandler)
Loads a track or playlist with the specified identifier.- 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:
loadItemSync(String, AudioLoadResultHandler)
-
loadItemSync
@Nullable default @Nullable AudioItem loadItemSync(java.lang.String reference)
Loads a track or playlist with the specified identifier and returns it.- 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. - See Also:
loadItemSync(AudioReference)
-
loadItemSync
@Nullable @Nullable AudioItem loadItemSync(AudioReference reference)
Loads a track or playlist with the specified identifier and returns it.- 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.
-
loadItemOrdered
default java.util.concurrent.Future<java.lang.Void> loadItemOrdered(java.lang.Object orderingKey, java.lang.String identifier, 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.- Parameters:
orderingKey- Object to use as the key for the ordering channelidentifier- 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:
loadItemOrdered(Object, AudioReference, AudioLoadResultHandler)
-
loadItemOrdered
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.- 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:
loadItemOrdered(Object, String, AudioLoadResultHandler)
-
encodeTrack
void encodeTrack(MessageOutput stream, AudioTrack track) throws java.io.IOException
Encode 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- Parameters:
stream- The message stream to write it to.track- The track to encode.- Throws:
java.io.IOException- On IO error.
-
decodeTrack
DecodedTrackHolder decodeTrack(MessageInput stream) throws java.io.IOException
Decode a track from an input stream. Null returns value indicates reaching the position where the decoder had called MessageOutput#finish().- 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.
-
getConfiguration
AudioConfiguration getConfiguration()
- Returns:
- Audio processing configuration used for tracks executed by this manager.
-
isUsingSeekGhosting
boolean isUsingSeekGhosting()
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.- Returns:
- True if seek ghosting is enabled.
-
setUseSeekGhosting
void setUseSeekGhosting(boolean useSeekGhosting)
- Parameters:
useSeekGhosting- The new state of seek ghosting
-
getFrameBufferDuration
int getFrameBufferDuration()
- Returns:
- The length of the internal buffer for audio in milliseconds.
-
setFrameBufferDuration
void setFrameBufferDuration(int frameBufferDuration)
- Parameters:
frameBufferDuration- New length of the internal buffer for audio in milliseconds.
-
setTrackStuckThreshold
void setTrackStuckThreshold(long trackStuckThreshold)
Sets 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.- Parameters:
trackStuckThreshold- The threshold in milliseconds.
-
setPlayerCleanupThreshold
void setPlayerCleanupThreshold(long cleanupThreshold)
Sets the threshold for clearing an audio player when it has not been queried for the specified amount of time.- Parameters:
cleanupThreshold- The threshold in milliseconds.
-
setItemLoaderThreadPoolSize
void setItemLoaderThreadPoolSize(int poolSize)
Sets the number of threads used for loading processing item load requests.- Parameters:
poolSize- Maximum number of concurrent threads used for loading items.
-
createPlayer
AudioPlayer createPlayer()
- Returns:
- New audio player.
-
setHttpRequestConfigurator
void setHttpRequestConfigurator(java.util.function.Function<org.apache.http.client.config.RequestConfig,org.apache.http.client.config.RequestConfig> configurator)
- 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
void setHttpBuilderConfigurator(java.util.function.Consumer<org.apache.http.impl.client.HttpClientBuilder> configurator)
- 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.
-
-