Package org.javacord.api.audio
Class AudioSourceBase
- java.lang.Object
-
- org.javacord.api.audio.AudioSourceBase
-
- All Implemented Interfaces:
AudioSource,AudioSourceAttachableListenerManager,Specializable<AudioSource>
- Direct Known Subclasses:
SilentAudioSource
public abstract class AudioSourceBase extends java.lang.Object implements AudioSource
The base class of every audio source.It already implements all methods required for listener handling, muting and the
hasFinished()method.
-
-
Constructor Summary
Constructors Constructor Description AudioSourceBase(DiscordApi api)Creates a new audio source base.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends AudioSourceAttachableListener & ObjectAttachableListener>
java.util.Collection<ListenerManager<T>>addAudioSourceAttachableListener(T listener)Adds a listener that implements one or moreAudioSourceAttachableListeners.ListenerManager<AudioSourceFinishedListener>addAudioSourceFinishedListener(AudioSourceFinishedListener listener)Adds aAudioSourceFinishedListener.voidaddTransformer(AudioTransformer transformer)Adds a transformer to the audio source.protected byte[]applyTransformers(byte[] frame)Transforms the given frame using the audio source's transformers.DiscordApigetApi()Gets the discord api instance for this audio source.<T extends AudioSourceAttachableListener & ObjectAttachableListener>
java.util.Map<T,java.util.List<java.lang.Class<T>>>getAudioSourceAttachableListeners()Gets a map with all registered listeners that implement one or moreAudioSourceAttachableListeners and their assigned listener classes they listen to.java.util.List<AudioSourceFinishedListener>getAudioSourceFinishedListeners()Gets a list with all registeredAudioSourceFinishedListeners.AudioSourceBaseDelegategetDelegate()Gets the delegate used by this audio source internally.java.util.List<AudioTransformer>getTransformers()Gets a list of all transformers of this audio source.booleanhasFinished()Checks whether the audio source has finished and can be dequeued.booleanisMuted()Checks whether the audio source is muted.<T extends AudioSourceAttachableListener & ObjectAttachableListener>
voidremoveAudioSourceAttachableListener(T listener)Removes a listener that implements one or moreAudioSourceAttachableListeners.<T extends AudioSourceAttachableListener & ObjectAttachableListener>
voidremoveListener(java.lang.Class<T> listenerClass, T listener)Removes a listener from this object.booleanremoveTransformer(AudioTransformer transformer)Removes a transformer from the audio source.voidremoveTransformers()Removes all transformers from the audio source.voidsetMuted(boolean muted)Sets whether the audio source should be muted.-
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
asBufferableAudioSource, asDownloadableAudioSource, asPauseableAudioSource, asSeekableAudioSource, copy, getNextFrame, hasNextFrame, mute, unmute
-
Methods inherited from interface org.javacord.api.util.Specializable
as
-
-
-
-
Constructor Detail
-
AudioSourceBase
public AudioSourceBase(DiscordApi api)
Creates a new audio source base.- Parameters:
api- The discord api instance.
-
-
Method Detail
-
getDelegate
public AudioSourceBaseDelegate getDelegate()
Gets the delegate used by this audio source internally.- Returns:
- The delegate used by this audio source internally.
-
applyTransformers
protected final byte[] applyTransformers(byte[] frame)
Transforms the given frame using the audio source's transformers.- Parameters:
frame- The frame to transform.- Returns:
- The transformed frame.
-
getApi
public final DiscordApi getApi()
Description copied from interface:AudioSourceGets the discord api instance for this audio source.- Specified by:
getApiin interfaceAudioSource- Returns:
- The discord api instance.
-
addTransformer
public final void addTransformer(AudioTransformer transformer)
Description copied from interface:AudioSourceAdds a transformer to the audio source.- Specified by:
addTransformerin interfaceAudioSource- Parameters:
transformer- The transformer.
-
removeTransformer
public final boolean removeTransformer(AudioTransformer transformer)
Description copied from interface:AudioSourceRemoves a transformer from the audio source.- Specified by:
removeTransformerin interfaceAudioSource- Parameters:
transformer- The transformer.- Returns:
- If the audio source contained the specified transformer.
-
getTransformers
public final java.util.List<AudioTransformer> getTransformers()
Description copied from interface:AudioSourceGets a list of all transformers of this audio source.- Specified by:
getTransformersin interfaceAudioSource- Returns:
- A list with all transformers.
-
removeTransformers
public final void removeTransformers()
Description copied from interface:AudioSourceRemoves all transformers from the audio source.- Specified by:
removeTransformersin interfaceAudioSource
-
isMuted
public boolean isMuted()
Description copied from interface:AudioSourceChecks whether the audio source is muted.- Specified by:
isMutedin interfaceAudioSource- Returns:
- Whether the audio source is muted.
-
setMuted
public void setMuted(boolean muted)
Description copied from interface:AudioSourceSets whether the audio source should be muted.A muted audio source will still continue. This means, that after unmuting the audio source will be at a different "position".
- Specified by:
setMutedin interfaceAudioSource- Parameters:
muted- Whether the audio source should be muted.
-
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- Returns:
- Whether the audio source has finished and can be dequeued.
-
addAudioSourceFinishedListener
public final ListenerManager<AudioSourceFinishedListener> addAudioSourceFinishedListener(AudioSourceFinishedListener listener)
Description copied from interface:AudioSourceAttachableListenerManagerAdds aAudioSourceFinishedListener.- Specified by:
addAudioSourceFinishedListenerin interfaceAudioSourceAttachableListenerManager- Parameters:
listener- The listener to add.- Returns:
- The manager of the listener.
-
getAudioSourceFinishedListeners
public final java.util.List<AudioSourceFinishedListener> getAudioSourceFinishedListeners()
Description copied from interface:AudioSourceAttachableListenerManagerGets a list with all registeredAudioSourceFinishedListeners.- Specified by:
getAudioSourceFinishedListenersin interfaceAudioSourceAttachableListenerManager- Returns:
- A list with all registered
AudioSourceFinishedListeners.
-
addAudioSourceAttachableListener
public final <T extends AudioSourceAttachableListener & ObjectAttachableListener> java.util.Collection<ListenerManager<T>> addAudioSourceAttachableListener(T listener)
Description copied from interface:AudioSourceAttachableListenerManagerAdds a listener that implements one or moreAudioSourceAttachableListeners. Adding a listener multiple times will only add it once and return the same listener managers on each invocation. The order of invocation is according to first addition.- Specified by:
addAudioSourceAttachableListenerin interfaceAudioSourceAttachableListenerManager- Type Parameters:
T- The type of the listener.- Parameters:
listener- The listener to add.- Returns:
- The managers for the added listener.
-
removeAudioSourceAttachableListener
public final <T extends AudioSourceAttachableListener & ObjectAttachableListener> void removeAudioSourceAttachableListener(T listener)
Description copied from interface:AudioSourceAttachableListenerManagerRemoves a listener that implements one or moreAudioSourceAttachableListeners.- Specified by:
removeAudioSourceAttachableListenerin interfaceAudioSourceAttachableListenerManager- Type Parameters:
T- The type of the listener.- Parameters:
listener- The listener to remove.
-
getAudioSourceAttachableListeners
public final <T extends AudioSourceAttachableListener & ObjectAttachableListener> java.util.Map<T,java.util.List<java.lang.Class<T>>> getAudioSourceAttachableListeners()
Description copied from interface:AudioSourceAttachableListenerManagerGets a map with all registered listeners that implement one or moreAudioSourceAttachableListeners and their assigned listener classes they listen to.- Specified by:
getAudioSourceAttachableListenersin interfaceAudioSourceAttachableListenerManager- Type Parameters:
T- The type of the listeners.- Returns:
- A map with all registered listeners that implement one or more
AudioSourceAttachableListeners and their assigned listener classes they listen to.
-
removeListener
public final <T extends AudioSourceAttachableListener & ObjectAttachableListener> void removeListener(java.lang.Class<T> listenerClass, T listener)
Description copied from interface:AudioSourceAttachableListenerManagerRemoves a listener from this object.- Specified by:
removeListenerin interfaceAudioSourceAttachableListenerManager- Type Parameters:
T- The type of the listener.- Parameters:
listenerClass- The listener class.listener- The listener to remove.
-
-