Interface AudioManager
-
public interface AudioManager
AudioManager deals with creating, managing and severing audio connections toVoiceChannels
. Also controls audio handlers.- See Also:
Guild.getAudioManager()
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_CONNECTION_TIMEOUT
static org.slf4j.Logger
LOG
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
closeAudioConnection()
Close down the current audio connection of thisGuild
and disconnects from theVoiceChannel
.VoiceChannel
getConnectedChannel()
TheVoiceChannel
that JDA currently has an audio connection to.ConnectionListener
getConnectionListener()
ConnectionStatus
getConnectionStatus()
The currentConnectionStatus
.long
getConnectTimeout()
The currently set timeout value, in milliseconds, used when waiting for an audio connection to be established.Guild
getGuild()
Gets theGuild
instance that this AudioManager is used for.JDA
getJDA()
Gets theJDA
instance that this AudioManager is a part of.VoiceChannel
getQueuedAudioConnection()
Deprecated.The internals have changed and this is no longer usedAudioReceiveHandler
getReceivingHandler()
The currently setAudioReceiveHandler
.AudioSendHandler
getSendingHandler()
The currently setAudioSendHandler
.java.util.EnumSet<SpeakingMode>
getSpeakingMode()
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
.boolean
isAttemptingToConnect()
Deprecated.The internals have changed and this is no longer usedboolean
isAutoReconnect()
Whether audio connections from this AudioManager automatically reconnectboolean
isConnected()
This can be used to find out if JDA currently has an active audio connection with aVoiceChannel
.boolean
isSelfDeafened()
Whether connections from this AudioManager are deafened.boolean
isSelfMuted()
Whether connections from this AudioManager are muted, if this istrue
packages by the registeredAudioSendHandler
will be ignored by Discord.void
openAudioConnection(VoiceChannel channel)
Starts the process to create an audio connection with aVoiceChannel
or, if an audio connection is already open, JDA will move the connection to the provided VoiceChannel.void
setAutoReconnect(boolean shouldReconnect)
Sets whether audio connections from this AudioManager should automatically reconnect or not.void
setConnectionListener(ConnectionListener listener)
Sets theConnectionListener
for this AudioManager.void
setConnectTimeout(long timeout)
Sets the amount of time, in milliseconds, that will be used as the timeout when waiting for the audio connection to successfully connect.void
setReceivingHandler(AudioReceiveHandler handler)
Sets theAudioReceiveHandler
that the manager will use to process audio data received from an audio connection.void
setSelfDeafened(boolean deafened)
Sets whether connections from this AudioManager should be deafened.void
setSelfMuted(boolean muted)
Set this totrue
if the current connection should be displayed as muted, this will cause theAudioSendHandler
packages to not be ignored by Discord!void
setSendingHandler(AudioSendHandler handler)
Sets theAudioSendHandler
that the manager will use to provide audio data to an audio connection.void
setSpeakingDelay(int millis)
Configures the delay between the last provided frame and removing the speaking indicator.void
setSpeakingMode(java.util.Collection<SpeakingMode> mode)
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
.default void
setSpeakingMode(SpeakingMode... mode)
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
.
-
-
-
Field Detail
-
DEFAULT_CONNECTION_TIMEOUT
static final long DEFAULT_CONNECTION_TIMEOUT
- See Also:
- Constant Field Values
-
LOG
static final org.slf4j.Logger LOG
-
-
Method Detail
-
openAudioConnection
void openAudioConnection(VoiceChannel channel)
Starts the process to create an audio connection with aVoiceChannel
or, if an audio connection is already open, JDA will move the connection to the provided VoiceChannel.
Note: Currently you can only be connected to a singleVoiceChannel
perGuild
.This method will automatically move the current connection if one connection is already open in this underlying
Guild
.
Current connections can be closed withcloseAudioConnection()
.Client accounts can only connect to a single
VoiceChannel
at once. It is an Account-Wide limitation!- Parameters:
channel
- TheVoiceChannel
to open an audio connection with.- Throws:
java.lang.IllegalArgumentException
-- If the provided channel was
null
. - If the provided channel is not part of the Guild that the current audio connection is connected to.
- If the provided channel was
java.lang.UnsupportedOperationException
- If audio is disabled due to an internal JDA errorInsufficientPermissionException
-- If the currently logged in account does not have the Permission
VOICE_CONNECT
- If the currently logged in account does not have the Permission
VOICE_MOVE_OTHERS
and theuser limit
has been exceeded!
- If the currently logged in account does not have the Permission
-
closeAudioConnection
void closeAudioConnection()
Close down the current audio connection of thisGuild
and disconnects from theVoiceChannel
.
If this is called when JDA doesn't have an audio connection, nothing happens.
-
setSpeakingMode
@Incubating void setSpeakingMode(@Nonnull java.util.Collection<SpeakingMode> mode)
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
. By default this will useSpeakingMode.VOICE
.
Example:EnumSet.of(SpeakingMode.PRIORITY_SPEAKER, SpeakingMode.VOICE)
- Parameters:
mode
- The speaking modes- Throws:
java.lang.IllegalArgumentException
- If the provided collection is null or empty- See Also:
getSpeakingMode()
,setSpeakingMode(SpeakingMode...)
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
setSpeakingMode
@Incubating default void setSpeakingMode(@Nonnull SpeakingMode... mode)
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
. By default this will useSpeakingMode.VOICE
.- Parameters:
mode
- The speaking modes- Throws:
java.lang.IllegalArgumentException
- If the provided array is null or empty- See Also:
getSpeakingMode()
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
getSpeakingMode
@Nonnull @Incubating java.util.EnumSet<SpeakingMode> getSpeakingMode()
TheSpeakingMode
that should be used when sending audio via the providedAudioSendHandler
fromsetSendingHandler(AudioSendHandler)
. By default this will useSpeakingMode.VOICE
.- Returns:
- The current speaking mode, represented in an
EnumSet
- See Also:
setSpeakingMode(Collection)
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
setSpeakingDelay
void setSpeakingDelay(int millis)
Configures the delay between the last provided frame and removing the speaking indicator.
This can be useful for send systems that buffer a certain interval of audio frames that will be sent. By default the delay is 200 milliseconds which is also the minimum delay.If the delay is less than 200 milliseconds it will use the minimum delay. The provided delay will be aligned to the audio frame length of 20 milliseconds by means of integer division. This means it will be rounded down to the next biggest multiple of 20.
Note that this delay is not reliable and operates entirely based on the send system polling times which can cause it to be released earlier or later than the provided delay specifies.
- Parameters:
millis
- The delay that should be used, in milliseconds- Since:
- 4.0.0
-
getJDA
@Nonnull JDA getJDA()
Gets theJDA
instance that this AudioManager is a part of.- Returns:
- The corresponding JDA instance
-
getGuild
@Nonnull Guild getGuild()
Gets theGuild
instance that this AudioManager is used for.- Returns:
- The Guild that this AudioManager manages.
-
isAttemptingToConnect
@Deprecated @ForRemoval(deadline="5.0.0") @DeprecatedSince("4.2.0") boolean isAttemptingToConnect()
Deprecated.The internals have changed and this is no longer usedThis can be used to find out if JDA is currently attempting to setup an audio connection.
If this returns true thengetQueuedAudioConnection()
will return theVoiceChannel
that JDA is attempting to setup an audio connection to.- Returns:
- True, if JDA is currently attempting to create an audio connection.
-
getQueuedAudioConnection
@Nullable @Deprecated @ForRemoval(deadline="5.0.0") @DeprecatedSince("4.2.0") VoiceChannel getQueuedAudioConnection()
Deprecated.The internals have changed and this is no longer usedThis can be used to find out whatVoiceChannel
JDA is currently attempting to setup an audio connection for. If JDA isn't trying to create an audio connection this will return null.
In addition, if JDA is already connected, this will return null. To determine if JDA is already has an audio connection with aVoiceChannel
useisConnected()
- Returns:
- The
VoiceChannel
that JDA is attempting to create an audio connection with, ornull
if JDA isn't attempting to create a connection.
-
getConnectedChannel
@Nullable VoiceChannel getConnectedChannel()
TheVoiceChannel
that JDA currently has an audio connection to. If JDA currently doesn't have an audio connection to aVoiceChannel
this will returnnull
.- Returns:
- The
VoiceChannel
the audio connection is connected to ornull
if not connected.
-
isConnected
boolean isConnected()
This can be used to find out if JDA currently has an active audio connection with aVoiceChannel
. If this returns true, thengetConnectedChannel()
will return theVoiceChannel
which JDA is connected to.- Returns:
- True, if JDA currently has an active audio connection.
-
setConnectTimeout
void setConnectTimeout(long timeout)
Sets the amount of time, in milliseconds, that will be used as the timeout when waiting for the audio connection to successfully connect. The default value is 10 second (10,000 milliseconds).
Note: If you set this value to 0, you can remove timeout functionality and JDA will wait FOREVER for the connection to be established. This is no advised as it is possible that the connection may never be established.- Parameters:
timeout
- The amount of time, in milliseconds, that should be waited when waiting for the audio connection to be established.
-
getConnectTimeout
long getConnectTimeout()
The currently set timeout value, in milliseconds, used when waiting for an audio connection to be established.- Returns:
- The currently set timeout.
-
setSendingHandler
void setSendingHandler(@Nullable AudioSendHandler handler)
Sets theAudioSendHandler
that the manager will use to provide audio data to an audio connection.
The handler provided here will persist between audio connection connect and disconnects. Furthermore, you don't need to have an audio connection to set a handler. When JDA sets up a new audio connection it will use the handler provided here.
Setting this to null will remove the audio handler.JDA recommends LavaPlayer as an
AudioSendHandler
. It provides a demo targeted at JDA users.- Parameters:
handler
- TheAudioSendHandler
used to provide audio data.
-
getSendingHandler
@Nullable AudioSendHandler getSendingHandler()
The currently setAudioSendHandler
. If there is no sender currently set, this method will returnnull
.- Returns:
- The currently active
AudioSendHandler
ornull
.
-
setReceivingHandler
void setReceivingHandler(@Nullable AudioReceiveHandler handler)
Sets theAudioReceiveHandler
that the manager will use to process audio data received from an audio connection.The handler provided here will persist between audio connection connect and disconnects. Furthermore, you don't need to have an audio connection to set a handler. When JDA sets up a new audio connection it will use the handler provided here.
Setting this to null will remove the audio handler.- Parameters:
handler
- TheAudioReceiveHandler
used to process received audio data.
-
getReceivingHandler
@Nullable AudioReceiveHandler getReceivingHandler()
The currently setAudioReceiveHandler
. If there is no receiver currently set, this method will returnnull
.- Returns:
- The currently active
AudioReceiveHandler
ornull
.
-
setConnectionListener
void setConnectionListener(@Nullable ConnectionListener listener)
Sets theConnectionListener
for this AudioManager. It will be informed about meta data of any audio connection established through this AudioManager. Further information can be found in theConnectionListener
documentation!- Parameters:
listener
- AConnectionListener
instance
-
getConnectionListener
@Nullable ConnectionListener getConnectionListener()
- Returns:
- The current
ConnectionListener
instance for this AudioManager.
-
getConnectionStatus
@Nonnull ConnectionStatus getConnectionStatus()
The currentConnectionStatus
.
This status indicates represents the connection status of an audio connection.- Returns:
- The current
ConnectionStatus
.
-
setAutoReconnect
void setAutoReconnect(boolean shouldReconnect)
Sets whether audio connections from this AudioManager should automatically reconnect or not. Defaulttrue
- Parameters:
shouldReconnect
- Whether audio connections from this AudioManager should automatically reconnect
-
isAutoReconnect
boolean isAutoReconnect()
Whether audio connections from this AudioManager automatically reconnect- Returns:
- Whether audio connections from this AudioManager automatically reconnect
-
setSelfMuted
void setSelfMuted(boolean muted)
Set this totrue
if the current connection should be displayed as muted, this will cause theAudioSendHandler
packages to not be ignored by Discord!- Parameters:
muted
- Whether the connection should stop sending audio and display as muted.
-
isSelfMuted
boolean isSelfMuted()
Whether connections from this AudioManager are muted, if this istrue
packages by the registeredAudioSendHandler
will be ignored by Discord.- Returns:
- Whether connections from this AudioManager are muted
-
setSelfDeafened
void setSelfDeafened(boolean deafened)
Sets whether connections from this AudioManager should be deafened.
This does not include being muted, that value can be set individually fromsetSelfMuted(boolean)
and checked viaisSelfMuted()
- Parameters:
deafened
- Whether connections from this AudioManager should be deafened.
-
isSelfDeafened
boolean isSelfDeafened()
Whether connections from this AudioManager are deafened.
This does not include being muted, that value can be set individually fromsetSelfMuted(boolean)
and checked viaisSelfMuted()
- Returns:
- True, if connections from this AudioManager are deafened
-
-