Class DefaultAudioPlayerManager

  • All Implemented Interfaces:
    AudioPlayerManager

    public class DefaultAudioPlayerManager
    extends java.lang.Object
    implements AudioPlayerManager
    The default implementation of audio player manager.
    • Constructor Detail

      • DefaultAudioPlayerManager

        public DefaultAudioPlayerManager()
        Create a new instance
    • Method Detail

      • shutdown

        public void shutdown()
        Description copied from interface: AudioPlayerManager
        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.

        Specified by:
        shutdown in interface AudioPlayerManager
      • enableGcMonitoring

        public void enableGcMonitoring()
        Description copied from interface: AudioPlayerManager
        Enable reporting GC pause length statistics to log (warn level with lengths bad for latency, debug level otherwise)
        Specified by:
        enableGcMonitoring in interface AudioPlayerManager
      • source

        public <T extends AudioSourceManager> T source​(java.lang.Class<T> klass)
        Description copied from interface: AudioPlayerManager
        Shortcut for accessing a source manager of a certain class.
        Specified by:
        source in interface AudioPlayerManager
        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.
      • loadItemSync

        @Nullable
        public @Nullable AudioItem loadItemSync​(AudioReference reference)
        Description copied from interface: AudioPlayerManager
        Loads a track or playlist with the specified identifier and returns it.
        Specified by:
        loadItemSync in interface AudioPlayerManager
        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.
      • loadItem

        public java.util.concurrent.Future<java.lang.Void> loadItem​(AudioReference reference,
                                                                    AudioLoadResultHandler resultHandler)
        Description copied from interface: AudioPlayerManager
        Schedules loading a track or playlist with the specified identifier.
        Specified by:
        loadItem in interface AudioPlayerManager
        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: AudioPlayerManager
        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.
        Specified by:
        loadItemOrdered in interface AudioPlayerManager
        Parameters:
        orderingKey - Object to use as the key for the ordering channel
        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.loadItemOrdered(Object, String, AudioLoadResultHandler)
      • encodeTrack

        public void encodeTrack​(MessageOutput stream,
                                AudioTrack track)
                         throws java.io.IOException
        Description copied from interface: AudioPlayerManager
        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
        Specified by:
        encodeTrack in interface AudioPlayerManager
        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: AudioPlayerManager
        Decode a track from an input stream. Null returns value indicates reaching the position where the decoder had called MessageOutput#finish().
        Specified by:
        decodeTrack in interface AudioPlayerManager
        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 decode
        buffer - 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 events
        track - The audio track to execute
        configuration - The audio configuration to use for executing
        playerOptions - Options of the audio player
      • isUsingSeekGhosting

        public boolean isUsingSeekGhosting()
        Description copied from interface: AudioPlayerManager
        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.
        Specified by:
        isUsingSeekGhosting in interface AudioPlayerManager
        Returns:
        True if seek ghosting is enabled.
      • setUseSeekGhosting

        public void setUseSeekGhosting​(boolean useSeekGhosting)
        Specified by:
        setUseSeekGhosting in interface AudioPlayerManager
        Parameters:
        useSeekGhosting - The new state of seek ghosting
      • getFrameBufferDuration

        public int getFrameBufferDuration()
        Specified by:
        getFrameBufferDuration in interface AudioPlayerManager
        Returns:
        The length of the internal buffer for audio in milliseconds.
      • setFrameBufferDuration

        public void setFrameBufferDuration​(int frameBufferDuration)
        Specified by:
        setFrameBufferDuration in interface AudioPlayerManager
        Parameters:
        frameBufferDuration - New length of the internal buffer for audio in milliseconds.
      • setTrackStuckThreshold

        public void setTrackStuckThreshold​(long trackStuckThreshold)
        Description copied from interface: AudioPlayerManager
        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.
        Specified by:
        setTrackStuckThreshold in interface AudioPlayerManager
        Parameters:
        trackStuckThreshold - The threshold in milliseconds.
      • getTrackStuckThresholdNanos

        public long getTrackStuckThresholdNanos()
      • setPlayerCleanupThreshold

        public void setPlayerCleanupThreshold​(long cleanupThreshold)
        Description copied from interface: AudioPlayerManager
        Sets the threshold for clearing an audio player when it has not been queried for the specified amount of time.
        Specified by:
        setPlayerCleanupThreshold in interface AudioPlayerManager
        Parameters:
        cleanupThreshold - The threshold in milliseconds.
      • setItemLoaderThreadPoolSize

        public void setItemLoaderThreadPoolSize​(int poolSize)
        Description copied from interface: AudioPlayerManager
        Sets the number of threads used for loading processing item load requests.
        Specified by:
        setItemLoaderThreadPoolSize in interface AudioPlayerManager
        Parameters:
        poolSize - Maximum number of concurrent threads used for loading items.
      • getExecutor

        public java.util.concurrent.ExecutorService getExecutor()
      • 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:
        setHttpRequestConfigurator in interface AudioPlayerManager
        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:
        setHttpBuilderConfigurator in interface AudioPlayerManager
        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.