Class SilentAudioSource
- java.lang.Object
-
- org.javacord.api.audio.AudioSourceBase
-
- org.javacord.api.audio.SilentAudioSource
-
- All Implemented Interfaces:
AudioSource,PauseableAudioSource,SeekableAudioSource,AudioSourceAttachableListenerManager,Specializable<AudioSource>
public class SilentAudioSource extends AudioSourceBase implements PauseableAudioSource, SeekableAudioSource
A silent audio source that's always muted.Can be used to create "gaps" between audio sources.
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]SILENCE_FRAMEA frame of silence.
-
Constructor Summary
Constructors Constructor Description SilentAudioSource(SilentAudioSource toCopy)Creates a new silent audio source and copies the duration settings from the given one.SilentAudioSource(DiscordApi api, long duration, java.util.concurrent.TimeUnit unit)Creates a new silent audio source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AudioSourcecopy()Creates a copy of the audio source that can be reused for another audio connection.java.time.DurationgetDuration()Gets the duration of the audio source.byte[]getNextFrame()Polls for the next 20ms of audio from the source.java.time.DurationgetPosition()Gets the position of the audio source.booleanhasFinished()Checks whether the audio source has finished and can be dequeued.booleanhasNextFrame()Checks whether there is 20ms of audio available to be polled.booleanisMuted()Checks whether the audio source is muted.booleanisPaused()Checks if the audio source is paused.voidsetPaused(boolean paused)Sets whether the audio source should be paused.longsetPosition(long position, java.util.concurrent.TimeUnit unit)Sets the position of the audio source.-
Methods inherited from class org.javacord.api.audio.AudioSourceBase
addAudioSourceAttachableListener, addAudioSourceFinishedListener, addTransformer, applyTransformers, getApi, getAudioSourceAttachableListeners, getAudioSourceFinishedListeners, getDelegate, getTransformers, removeAudioSourceAttachableListener, removeListener, removeTransformer, removeTransformers, setMuted
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.javacord.api.audio.AudioSource
addTransformer, asBufferableAudioSource, asDownloadableAudioSource, asPauseableAudioSource, asSeekableAudioSource, getApi, getTransformers, mute, removeTransformer, removeTransformers, setMuted, unmute
-
Methods inherited from interface org.javacord.api.listener.audio.AudioSourceAttachableListenerManager
addAudioSourceAttachableListener, addAudioSourceFinishedListener, getAudioSourceAttachableListeners, getAudioSourceFinishedListeners, removeAudioSourceAttachableListener, removeListener
-
Methods inherited from interface org.javacord.api.audio.PauseableAudioSource
pause, resume
-
Methods inherited from interface org.javacord.api.util.Specializable
as
-
-
-
-
Constructor Detail
-
SilentAudioSource
public SilentAudioSource(DiscordApi api, long duration, java.util.concurrent.TimeUnit unit)
Creates a new silent audio source.As audio frames always have a fixed
20msduration, the duration will be rounded down to the closest multiple of20ms. E.g. when trying to set the duration to79ms, the duration will instead be set to60ms.- Parameters:
api- The discord api instance.duration- How long it should be silent.unit- ATimeUnitdetermining how to interpret thedurationparameter. As audio frames have a fixed size of20ms, units bellowTimeUnit.MILLISECONDSare 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
-
getNextFrame
public byte[] getNextFrame()
Description copied from interface:AudioSourcePolls for the next 20ms of audio from the source.- Specified by:
getNextFramein interfaceAudioSource- Returns:
- A byte array containing 20ms of audio, or null if
AudioSource.hasNextFrame()is false.
-
hasNextFrame
public boolean hasNextFrame()
Description copied from interface:AudioSourceChecks 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:
hasNextFramein interfaceAudioSource- Returns:
- Whether there is a frame available to be polled.
-
hasFinished
public boolean hasFinished()
Description copied from interface:AudioSourceChecks 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:
hasFinishedin interfaceAudioSource- Overrides:
hasFinishedin classAudioSourceBase- Returns:
- Whether the audio source has finished and can be dequeued.
-
isMuted
public boolean isMuted()
Description copied from interface:AudioSourceChecks whether the audio source is muted.- Specified by:
isMutedin interfaceAudioSource- Overrides:
isMutedin classAudioSourceBase- Returns:
- Whether the audio source is muted.
-
copy
public AudioSource copy()
Description copied from interface:AudioSourceCreates 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:
copyin interfaceAudioSource- Returns:
- A copy of the audio source.
-
setPaused
public void setPaused(boolean paused)
Description copied from interface:PauseableAudioSourceSets 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:
setPausedin interfacePauseableAudioSource- Parameters:
paused- Whether the audio source should be paused.
-
isPaused
public boolean isPaused()
Description copied from interface:PauseableAudioSourceChecks if the audio source is paused.- Specified by:
isPausedin interfacePauseableAudioSource- Returns:
- Whether the audio source is paused or not.
-
setPosition
public long setPosition(long position, java.util.concurrent.TimeUnit unit)Description copied from interface:SeekableAudioSourceSets the position of the audio source.As audio frames always have a fixed
20msduration, the position will be rounded down to the closest multiple of20ms. E.g. when callingsetPosition(79, TimeUnit.MILLISECONDS), the position will instead be set to60ms.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:
setPositionin interfaceSeekableAudioSource- Parameters:
position- The position to jump to.unit- ATimeUnitdetermining how to interpret thepositionparameter. As audio frames have a fixed size of20ms, units bellowTimeUnit.MILLISECONDSare not recommended.- Returns:
- The new position of the audio source in the given time unit.
-
getPosition
public java.time.Duration getPosition()
Description copied from interface:SeekableAudioSourceGets the position of the audio source.- Specified by:
getPositionin interfaceSeekableAudioSource- Returns:
- The position of the audio source.
-
getDuration
public java.time.Duration getDuration()
Description copied from interface:SeekableAudioSourceGets the duration of the audio source.- Specified by:
getDurationin interfaceSeekableAudioSource- Returns:
- The duration of the audio source.
-
-