Interface BufferableAudioSource
-
- All Superinterfaces:
AudioSource
,AudioSourceAttachableListenerManager
,Specializable<AudioSource>
public interface BufferableAudioSource extends AudioSource
A bufferable audio source.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.time.Duration
getBufferSize()
Gets the size of the buffer.java.time.Duration
getUsedBufferSize()
Gets the current used size of the buffer.void
setBufferSize(long size, java.util.concurrent.TimeUnit unit)
Sets the buffer size of the audio source.-
Methods inherited from interface org.javacord.api.audio.AudioSource
addTransformer, asBufferableAudioSource, asDownloadableAudioSource, asPauseableAudioSource, asSeekableAudioSource, copy, getApi, getNextFrame, getTransformers, hasFinished, hasNextFrame, isMuted, 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.util.Specializable
as
-
-
-
-
Method Detail
-
setBufferSize
void setBufferSize(long size, java.util.concurrent.TimeUnit unit)
Sets the buffer size of the audio source.The audio source will pre-download audio frames for the specified buffer size to allow for a smooth playback without stuttering.
As audio frames always have a fixed
20ms
duration, the buffer size will be rounded down to the closest multiple of20ms
. E.g. when callingsetBufferSize(79, TimeUnit.MILLISECONDS)
, the buffer size will instead be set to60ms
.Depending on the audio source, it might not be possible to buffer in 20ms accuracy. In this case, it will try to get as close to the actual buffer size as possible.
Negative buffer sizes will be interpreted as
0
.- Parameters:
size
- The size of the buffer.unit
- ATimeUnit
determining how to interpret thesize
parameter. As audio frames have a fixed size of20ms
, units bellowTimeUnit.MILLISECONDS
are not recommended.
-
getBufferSize
java.time.Duration getBufferSize()
Gets the size of the buffer.- Returns:
- The buffer size of the audio source.
-
getUsedBufferSize
java.time.Duration getUsedBufferSize()
Gets the current used size of the buffer.Unlike
getBufferSize()
, this method does not return how much can be buffered, but what's currently buffered.Notice, that it's possible, that the used buffer might exceed the allowed buffer size in some cases.
- Returns:
- The used buffer size of the audio source.
-
-