Package net.dv8tion.jda.api.managers
Interface AudioManager
public interface AudioManager
AudioManager deals with creating, managing and severing audio connections to
VoiceChannels. Also controls audio handlers.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final org.slf4j.Logger -
Method Summary
Modifier and TypeMethodDescriptionvoidClose down the current audio connection of thisGuildand disconnects from theAudioChannel.TheAudioChannelUnionthat JDA currently has an audio connection to.The currentConnectionStatus.longThe currently set timeout value, in milliseconds, used when waiting for an audio connection to be established.getGuild()Gets theGuildinstance that this AudioManager is used for.getJDA()Gets theJDAinstance that this AudioManager is a part of.The currently setAudioReceiveHandler.The currently setAudioSendHandler.TheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler).booleanWhether audio connections from this AudioManager automatically reconnectbooleanThis can be used to find out if JDA currently has an active audio connection with aAudioChannel.booleanWhether connections from this AudioManager are deafened.booleanWhether connections from this AudioManager are muted, if this istruepackages by the registeredAudioSendHandlerwill be ignored by Discord.voidopenAudioConnection(AudioChannel channel) Starts the process to create an audio connection with anAudioChannelor, if an audio connection is already open, JDA will move the connection to the provided AudioChannel.voidsetAutoReconnect(boolean shouldReconnect) Sets whether audio connections from this AudioManager should automatically reconnect or not.voidsetConnectionListener(ConnectionListener listener) Sets theConnectionListenerfor this AudioManager.voidsetConnectTimeout(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.voidsetReceivingHandler(AudioReceiveHandler handler) Sets theAudioReceiveHandlerthat the manager will use to process audio data received from an audio connection.voidsetSelfDeafened(boolean deafened) Sets whether connections from this AudioManager should be deafened.voidsetSelfMuted(boolean muted) Set this totrueif the current connection should be displayed as muted, this will cause theAudioSendHandlerpackages to not be ignored by Discord!voidsetSendingHandler(AudioSendHandler handler) Sets theAudioSendHandlerthat the manager will use to provide audio data to an audio connection.voidTheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler).default voidsetSpeakingMode(SpeakingMode... mode) TheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler).
-
Field Details
-
DEFAULT_CONNECTION_TIMEOUT
static final long DEFAULT_CONNECTION_TIMEOUT- See Also:
-
LOG
static final org.slf4j.Logger LOG
-
-
Method Details
-
openAudioConnection
Starts the process to create an audio connection with anAudioChannelor, if an audio connection is already open, JDA will move the connection to the provided AudioChannel.
Note: Currently you can only be connected to a singleAudioChannelperGuild.This method will automatically move the current connection if one connection is already open in this underlying
Guild.
Current connections can be closed withcloseAudioConnection().- Parameters:
channel- TheAudioChannelto open an audio connection with.- Throws:
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
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_OTHERSand theuser limithas been exceeded!
- If the currently logged in account does not have the Permission
-
closeAudioConnection
void closeAudioConnection()Close down the current audio connection of thisGuildand disconnects from theAudioChannel.
If this is called when JDA doesn't have an audio connection, nothing happens. -
setSpeakingMode
TheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler). By default this will useSpeakingMode.VOICE.
Example:EnumSet.of(SpeakingMode.PRIORITY_SPEAKER, SpeakingMode.VOICE)- Parameters:
mode- The speaking modes- Throws:
IllegalArgumentException- If the provided collection is null or empty- See Also:
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
setSpeakingMode
TheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler). By default this will useSpeakingMode.VOICE.- Parameters:
mode- The speaking modes- Throws:
IllegalArgumentException- If the provided array is null or empty- See Also:
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
getSpeakingMode
TheSpeakingModethat should be used when sending audio via the providedAudioSendHandlerfromsetSendingHandler(AudioSendHandler). By default this will useSpeakingMode.VOICE.- Returns:
- The current speaking mode, represented in an
EnumSet - See Also:
- Incubating:
- Discord has not officially confirmed that this feature will be available to bots
-
getJDA
Gets theJDAinstance that this AudioManager is a part of.- Returns:
- The corresponding JDA instance
-
getGuild
Gets theGuildinstance that this AudioManager is used for.- Returns:
- The Guild that this AudioManager manages.
-
getConnectedChannel
TheAudioChannelUnionthat JDA currently has an audio connection to.
If JDA currently doesn't have an active audio connection, this will returnnull.- Returns:
- The
AudioChannelUnionthe audio connection is connected to, ornullif not connected.
-
isConnected
boolean isConnected()This can be used to find out if JDA currently has an active audio connection with aAudioChannel. If this returns true, thengetConnectedChannel()will return theAudioChannelwhich 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
Sets theAudioSendHandlerthat the manager will use to provide audio data to an audio connection.
The handler provided here will persist between audio connection connects 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- TheAudioSendHandlerused to provide audio data.
-
getSendingHandler
The currently setAudioSendHandler. If there is no sender currently set, this method will returnnull.- Returns:
- The currently active
AudioSendHandlerornull.
-
setReceivingHandler
Sets theAudioReceiveHandlerthat 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- TheAudioReceiveHandlerused to process received audio data.
-
getReceivingHandler
The currently setAudioReceiveHandler. If there is no receiver currently set, this method will returnnull.- Returns:
- The currently active
AudioReceiveHandlerornull.
-
setConnectionListener
Sets theConnectionListenerfor this AudioManager. It will be informed about meta data of any audio connection established through this AudioManager. Further information can be found in theConnectionListenerdocumentation!- Parameters:
listener- AConnectionListenerinstance
-
getConnectionListener
- Returns:
- The current
ConnectionListenerinstance for this AudioManager.
-
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 totrueif the current connection should be displayed as muted, this will cause theAudioSendHandlerpackages 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 istruepackages by the registeredAudioSendHandlerwill 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
-