Class SilentAudioSource

    • Field Detail

      • SILENCE_FRAME

        public static final byte[] SILENCE_FRAME
        A frame of silence.
    • Constructor Detail

      • SilentAudioSource

        public SilentAudioSource​(DiscordApi api,
                                 long duration,
                                 TimeUnit unit)
        Creates a new silent audio source.

        As audio frames always have a fixed 20ms duration, the duration will be rounded down to the closest multiple of 20ms. E.g. when trying to set the duration to 79ms, the duration will instead be set to 60ms.

        Parameters:
        api - The discord api instance.
        duration - How long it should be silent.
        unit - A TimeUnit determining how to interpret the duration parameter. As audio frames have a fixed size of 20ms, units bellow TimeUnit.MILLISECONDS are not recommended.
      • SilentAudioSource

        public SilentAudioSource​(SilentAudioSource toCopy)
        Creates a new silent audio source and copies the duration settings from the given one.

        Does not copy the state of the audio source, e.g. if it is muted, it's transformers, etc.

        Parameters:
        toCopy - The silent audio source to copy from.
    • Method Detail

      • hasNextFrame

        public boolean hasNextFrame​()
        Description copied from interface: AudioSource
        Checks whether there is 20ms of audio available to be polled.

        If there is no frame available, but the source has not been finished, it will play a silent sound instead.

        Specified by:
        hasNextFrame in interface AudioSource
        Returns:
        Whether or not there is a frame available to be polled.
      • hasFinished

        public boolean hasFinished​()
        Description copied from interface: AudioSource
        Checks whether the audio source has finished and can be dequeued.

        This should not be confused with AudioSource.hasNextFrame() which only indicated if there is a frame available right now. An audio source might have no frame available, but is still not finished, e.g. because it's streaming something but downloads it too slowly.

        Specified by:
        hasFinished in interface AudioSource
        Overrides:
        hasFinished in class AudioSourceBase
        Returns:
        Whether the audio source has finished and can be dequeued.
      • isMuted

        public boolean isMuted​()
        Description copied from interface: AudioSource
        Checks whether the audio source is muted.
        Specified by:
        isMuted in interface AudioSource
        Overrides:
        isMuted in class AudioSourceBase
        Returns:
        Whether the audio source is muted.
      • copy

        public AudioSource copy​()
        Description copied from interface: AudioSource
        Creates a copy of the audio source that can be reused for another audio connection.

        Does not copy the state of the audio source, e.g. if it is muted, it's transformers, etc.

        Specified by:
        copy in interface AudioSource
        Returns:
        A copy of the audio source.
      • setPaused

        public void setPaused​(boolean paused)
        Description copied from interface: PauseableAudioSource
        Sets whether the audio source should be paused.

        A paused audio source will completely stop. This means, that after unpausing the audio source will continue at the same "position".

        Specified by:
        setPaused in interface PauseableAudioSource
        Parameters:
        paused - Whether the audio source should be paused.
      • isPaused

        public boolean isPaused​()
        Description copied from interface: PauseableAudioSource
        Checks if the audio source is paused.
        Specified by:
        isPaused in interface PauseableAudioSource
        Returns:
        Whether the audio source is paused or not.
      • setPosition

        public long setPosition​(long position,
                                TimeUnit unit)
        Description copied from interface: SeekableAudioSource
        Sets the position of the audio source.

        As audio frames always have a fixed 20ms duration, the position will be rounded down to the closest multiple of 20ms. E.g. when calling setPosition(79, TimeUnit.MILLISECONDS), the position will instead be set to 60ms.

        Attempting to set the position to a value that's larger than the audio source's duration, will instead set it to the maximum duration of the audio source.

        Negative positions will be interpreted as 0.

        Specified by:
        setPosition in interface SeekableAudioSource
        Parameters:
        position - The position to jump to.
        unit - A TimeUnit determining how to interpret the position parameter. As audio frames have a fixed size of 20ms, units bellow TimeUnit.MILLISECONDS are not recommended.
        Returns:
        The new position of the audio source in the given time unit.