Class DefaultAudioPlayer

    • Constructor Detail

      • DefaultAudioPlayer

        public DefaultAudioPlayer​(DefaultAudioPlayerManager manager)
        Parameters:
        manager - Audio player manager which this player is attached to
    • Method Detail

      • playTrack

        public void playTrack​(AudioTrack track)
        Specified by:
        playTrack in interface AudioPlayer
        Parameters:
        track - The track to start playing
      • startTrack

        public boolean startTrack​(AudioTrack track,
                                  boolean noInterrupt)
        Specified by:
        startTrack in interface AudioPlayer
        Parameters:
        track - The track to start playing, passing null will stop the current track and return false
        noInterrupt - Whether to only start if nothing else is playing
        Returns:
        True if the track was started
      • stopTrack

        public void stopTrack()
        Stop currently playing track.
        Specified by:
        stopTrack in interface AudioPlayer
      • provide

        public AudioFrame provide​(long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.util.concurrent.TimeoutException,
                                  java.lang.InterruptedException
        Specified by:
        provide in interface AudioFrameProvider
        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:
        provide in interface AudioFrameProvider
        Parameters:
        targetFrame - Frame to update with the details and data of the provided frame.
        Returns:
        true if 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:
        provide in interface AudioFrameProvider
        Parameters:
        targetFrame - Frame to update with the details and data of the provided frame.
        timeout - Timeout.
        unit - Time unit for the timeout value.
        Returns:
        true if 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).
      • setVolume

        public void setVolume​(int volume)
        Specified by:
        setVolume in interface AudioPlayer
      • isPaused

        public boolean isPaused()
        Specified by:
        isPaused in interface AudioPlayer
        Returns:
        Whether the player is paused
      • setPaused

        public void setPaused​(boolean value)
        Specified by:
        setPaused in interface AudioPlayer
        Parameters:
        value - True to pause, false to resume
      • destroy

        public void destroy()
        Destroy the player and stop playing track.
        Specified by:
        destroy in interface AudioPlayer
      • addListener

        public void addListener​(AudioEventListener listener)
        Add a listener to events from this player.
        Specified by:
        addListener in interface AudioPlayer
        Parameters:
        listener - New listener
      • removeListener

        public void removeListener​(AudioEventListener listener)
        Remove an attached listener using identity comparison.
        Specified by:
        removeListener in interface AudioPlayer
        Parameters:
        listener - The listener to remove
      • onTrackException

        public void onTrackException​(AudioTrack track,
                                     FriendlyException exception)
        Description copied from interface: TrackStateListener
        Called when an exception occurs while a track is playing or loading. This is always fatal, but it may have left some data in the audio buffer which can still play until the buffer clears out.
        Specified by:
        onTrackException in interface TrackStateListener
        Parameters:
        track - The audio track for which the exception occurred
        exception - The exception that occurred
      • onTrackStuck

        public void onTrackStuck​(AudioTrack track,
                                 long thresholdMs)
        Description copied from interface: TrackStateListener
        Called when an exception occurs while a track is playing or loading. This is always fatal, but it may have left some data in the audio buffer which can still play until the buffer clears out.
        Specified by:
        onTrackStuck in interface TrackStateListener
        Parameters:
        track - The audio track for which the exception occurred
        thresholdMs - The wait threshold that was exceeded for this event to trigger
      • checkCleanup

        public void checkCleanup​(long threshold)
        Check if the player should be "cleaned up" - stopped due to nothing using it, with the given threshold.
        Specified by:
        checkCleanup in interface AudioPlayer
        Parameters:
        threshold - Threshold in milliseconds to use