IRtcEngineEventHandler

IRtcEngineEventHandlerThe SDK uses the interface to send event notifications to your app. Your app can get those notifications through methods that inherit this interface.

All methods in this interface have default (empty) implementation. You can choose to inherit events related to your app scenario.

Attention:
  • In the callbacks, avoid implementing time-consuming tasks or calling APIs that may cause thread blocking (such as sendMessage). Otherwise, the SDK may not work properly.
  • The SDK no longer catches exceptions in the code logic that developers implement themselves in IRtcEngineEventHandler class. You need to handle this exception yourself, otherwise the app may crash when the exception occurs.

onActiveSpeaker

Occurs when the most active remote speaker is detected.

public void onActiveSpeaker(int uid) {}

After a successful call of enableAudioVolumeIndication, the SDK continuously detects which remote user has the loudest volume. During the current period, the remote user, who is detected as the loudest for the most times, is the most active user.

When the number of users is no less than two and an active remote speaker exists, the SDK triggers this callback and reports the uid of the most active remote speaker.
  • If the most active remote speaker is always the same user, the SDK triggers the onActiveSpeaker callback only once.
  • If the most active remote speaker changes to another user, the SDK triggers this callback again and reports the uid of the new active remote speaker.

Parameters

uid
The user ID of the most active remote speaker.

onApiCallExecuted

Occurs when a method is executed by the SDK.

public void onApiCallExecuted(int error, String api, String result) {}

Parameters

error
The error code returned by the SDK when the method call fails. If the SDK returns 0, then the method call is successful.
api
The method executed by the SDK.
result
The result of the method call.

onAudioEffectFinished

Occurs when the playback of the local music file finishes.

public void onAudioEffectFinished(int soundId) {}

This callback occurs when the local audio effect file finishes playing.

Parameters

soundId
The audio effect ID. The ID of each audio effect file is unique.

onAudioMixingFinished

Occurs when the playback of the local music file finishes.

public void onAudioMixingFinished() {}
Deprecated:
Please use onAudioMixingStateChanged instead.

After you call startAudioMixing [2/2] to play a local music file, this callback occurs when the playback finishes. If the call startAudioMixing [2/2] fails, the error code WARN_AUDIO_MIXING_OPEN_ERROR is returned.

onAudioMixingStateChanged

Occurs when the playback state of the music file changes.

public void onAudioMixingStateChanged(int state, int reasonCode);

This callback occurs when the playback state of the music file changes, and reports the current state and error code.

Parameters

state
The playback state of the music file.
  • AUDIO_MIXING_STATE_PLAYING(710): The music file is playing.
  • AUDIO_MIXING_STATE_PAUSED(711): The music file pauses playing.
  • AUDIO_MIXING_STATE_STOPPED(713): The music file stops playing.
  • AUDIO_MIXING_STATE_FAILED(714): An exception occurs when playing the audio mixing file. The SDK returns the specific reason for the error in the errorCode parameter.
reasonCode
Error code.
  • AUDIO_MIXING_REASON_OK(0): No error.
  • AUDIO_MIXING_REASON_CAN_NOT_OPEN701: The SDK cannot open the music file.
  • AUDIO_MIXING_REASON_TOO_FREQUENT_CALL702: The SDK opens the music file too frequently.
  • AUDIO_MIXING_REASON_INTERRUPTED_EOF703: The music file playback is interrupted.
  • AUDIO_MIXING_REASON_ONE_LOOP_COMPLETED(721): The music file completes a loop playback.
  • AUDIO_MIXING_REASON_ALL_LOOPS_COMPLETEDD(723): The music file completes all loop playback.
  • AUDIO_MIXING_REASON_STOPPED_BY_USER(725): The music file pauses playing by calling pauseAudioMixing.

onAudioPublishStateChanged

Occurs when the audio publishing state changes.

public void onAudioPublishStateChanged(String channel, STREAM_PUBLISH_STATE oldState,
      STREAM_PUBLISH_STATE newState, int elapseSinceLastState) {}

Parameters

channel
The channel name.
oldState
The previous subscribing status. See STREAM_PUBLISH_STATE.
newState
The current subscribing status. See STREAM_PUBLISH_STATE.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

onAudioQuality

Reports the statistics of the audio stream from each remote user.

public void onAudioQuality(int uid, int quality, short delay, short lost) {}
Deprecated:
Please use onRemoteAudioStats instead.

The SDK triggers this callback once every two seconds to report the audio quality of each remote user/host sending an audio stream. If a channel has multiple users/hosts sending audio streams, the SDK triggers this callback as many times.

Parameters

uid
The user ID of the remote user sending the audio stream.
quality
Audio quality of the user.
  • QUALITY_UNKNOWN(0): The quality is unknown.
  • QUALITY_EXCELLENT(1): The quality is excellent.
  • QUALITY_GOOD(2): The network quality seems excellent, but the bitrate can be slightly lower than excellent.
  • QUALITY_POOR(3): Users can feel the communication is slightly impaired.
  • QUALITY_BAD(4): Users cannot communicate smoothly.
  • QUALITY_VBAD(5): The quality is so bad that users can barely communicate.
  • QUALITY_DOWN(6): The network is down, and users cannot communicate at all.
delay
The network delay (ms) from the sender to the receiver, including the delay caused by audio sampling pre-processing, network transmission, and network jitter buffering.
lost
The packet loss rate (%) of the audio packet sent from the remote user.

onAudioRouteChanged

Occurs when the local audio route changes.

public void onAudioRoutingChanged(int routing) {}

Parameters

routing
The current audio routing.
  • AUDIO_ROUTE_DEFAULT(-1): Default audio route.
  • AUDIO_ROUTE_HEADSET(0): The audio route is a headset with a microphone.
  • AUDIO_ROUTE_EARPIECE(1): The audio route is an earpiece.
  • AUDIO_ROUTE_HEADSETNOMIC(2): The audio route is a headset without a microphone.
  • AUDIO_ROUTE_SPEAKERPHONE(3): The audio route is the speaker that comes with the device.
  • AUDIO_ROUTE_LOUDSPEAKER(4): (For future use) The audio route is an external speaker.
  • AUDIO_ROUTE_BLUETOOTH(5): The audio route is a Bluetooth headset.

onAudioSubscribeStateChanged

Occurs when the audio subscribing state changes.

public void onAudioSubscribeStateChanged(
    String channel, int uid, int oldState, int newState, int elapseSinceLastState) {}

Parameters

channel
The channel name.
uid
The user ID of the remote user.
oldState
The previous subscription status.
newState
The current subscribing status.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

onAudioVolumeIndication

Reports the volume information of users.

public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) {}

By default, this callback is disabled. You can enable it by calling enableAudioVolumeIndication. Once this callback is enabled and users send streams in the channel, the SDK triggers the onAudioVolumeIndication callback according to the time interval set in enableAudioVolumeIndication. The SDK triggers two independent onAudioVolumeIndication callbacks simultaneously, which separately report the volume information of the local user who sends a stream and the remote users (up to three) whose instantaneous volume is the highest.

Attention:

Once this callback is enabled, if the local user calls the muteLocalAudioStream method for mute, the SDK continues to report the volume indication of the local user.

20 seconds after a remote user whose volume is one of the three highest in the channel stops publishing the audio stream, the callback excludes this user's information; 20 seconds after all remote users stop publishing audio streams, the SDK stops triggering the callback for remote users.

Parameters

speakers
The volume information of the users. See AudioVolumeInfo. An empty speakers array in the callback indicates that no remote user is in the channel or sending a stream at the moment.
totalVolume
The volume of the speaker. The value ranges between 0 (lowest volume) and 255 (highest volume).
  • In the callback for the local user, totalVolume is the volume of the local user who sends a stream.
  • In the callback for remote users, totalVolume is the sum of the volume of the remote users (up to three) whose instantaneous volume are the highest. If the user calls startAudioMixing [2/2], totalVolume is the volume after audio mixing.

onCameraExposureAreaChanged

Occurs when the camera exposure area changes.

public void onCameraExposureAreaChanged(Rect rect) {}

The SDK triggers this callback when the local user changes the camera exposure position by calling setCameraExposurePosition.

Parameters

rect
The focus rectangle in the local preview.

onCameraFocusAreaChanged

Occurs when the camera focus area changes.

public void onCameraFocusAreaChanged(Rect rect) {}

The SDK triggers this callback when the local user changes the camera focus position by calling setCameraFocusPositionInPreview.

Parameters

rect
The focus rectangle in the local preview.

onCameraReady

Occurs when the camera turns on and is ready to capture the video.

public void onCameraReady() {}
Deprecated:

Please use LOCAL_VIDEO_STREAM_STATE_CAPTURING(1) in onLocalVideoStateChanged instead.

This callback indicates that the camera has been successfully turned on and you can start to capture video.

onChannelMediaRelayEvent

Reports events during the media stream relay.

public void onChannelMediaRelayEvent(int code) {}

Parameters

code
The event code of channel media relay:
  • RELAY_EVENT_NETWORK_DISCONNECTED(0): The user disconnects from the server due to a poor network connection.
  • RELAY_EVENT_NETWORK_CONNECTED(1): The user is connected to the server.
  • RELAY_EVENT_PACKET_JOINED_SRC_CHANNEL(2): The user joins the source channel.
  • RELAY_EVENT_PACKET_JOINED_DEST_CHANNEL(3): The user joins the destination channel.
  • RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL(4): The SDK starts relaying the media stream to the destination channel.
  • RELAY_EVENT_PACKET_RECEIVED_VIDEO_FROM_SRC(5): The server receives the video stream from the source channel.
  • RELAY_EVENT_PACKET_RECEIVED_AUDIO_FROM_SRC(6): The server receives the audio stream from the source channel.
  • RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL(7): The destination channel is updated.
  • RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_REFUSED(8): The destination channel update fails due to internal reasons.
  • RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE(9): The destination channel does not change, which means that the destination channel fails to be updated.
  • RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_IS_NULL(10): The destination channel name is NULL.
  • RELAY_EVENT_VIDEO_PROFILE_UPDATE(11): The video profile is sent to the server.
  • RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS(12): The SDK successfully pauses relaying the media stream to destination channels.
  • RELAY_EVENT_PAUSE_SEND_PACKET_TO_DEST_CHANNEL_FAILED(13): The SDK fails to pause relaying the media stream to destination channels.
  • RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_SUCCESS(14): The SDK successfully resumes relaying the media stream to destination channels.
  • RELAY_EVENT_RESUME_SEND_PACKET_TO_DEST_CHANNEL_FAILED(15): The SDK fails to resume relaying the media stream to destination channels.

onChannelMediaRelayStateChanged

Occurs when the state of the media stream relay changes.

public void onChannelMediaRelayStateChanged(int state, int code) {}

The SDK returns the state of the current media relay with any error message.

Parameters

state
The state code:
  • RELAY_STATE_IDLE(0): The SDK is initializing.
  • RELAY_STATE_CONNECTING(1): The SDK tries to relay the media stream to the destination channel.
  • RELAY_STATE_RUNNING(2): The SDK successfully relays the media stream to the destination channel.
  • RELAY_STATE_FAILURE(3): An error occurs. See code for the error code.
code
The error code of the channel media relay.
  • RELAY_OK(0): Everything is normal.
  • RELAY_ERROR_SERVER_ERROR_RESPONSE(1): An error occurs in the server response.
  • RELAY_ERROR_SERVER_NO_RESPONSE(2): No server response. You can call leaveChannel [1/2] to leave the channel. This error can also occur if your project has not enabled co-host token authentication. You can contact technical support to enable the service for cohosting across channels before starting a channel media relay.
  • RELAY_ERROR_NO_RESOURCE_AVAILABLE(3): The SDK fails to access the service, probably due to limited resources of the server.
  • RELAY_ERROR_FAILED_JOIN_SRC(4): The server fails to send the relay request.
  • RELAY_ERROR_FAILED_JOIN_DEST(5): The server fails to accept the relay request.
  • RELAY_ERROR_FAILED_PACKET_RECEIVED_FROM_SRC(6): The server fails to receive the media stream.
  • RELAY_ERROR_FAILED_PACKET_SENT_TO_DEST(7): The server fails to send the media stream.
  • RELAY_ERROR_SERVER_CONNECTION_LOST(8): The SDK disconnects from the server due to poor network connections. You can call leaveChannel [1/2] method to leave the channel.
  • RELAY_ERROR_INTERNAL_ERROR(9): An internal error occurs in the server.
  • RELAY_ERROR_SRC_TOKEN_EXPIRED(10): The token of the source channel has expired.
  • RELAY_ERROR_DEST_TOKEN_EXPIRED(11): The token of the destination channel has expired.

onClientRoleChanged

Occurs when the user role switches in the interactive live streaming.

public void onClientRoleChanged(int oldRole, int newRole) {}

The SDK triggers this callback when the local user switches the user role by calling setClientRole [1/2] after joining the channel.

Parameters

oldRole
Role that the user switches from:
  • CLIENT_ROLE_BROADCASTER(1): Host.
  • CLIENT_ROLE_AUDIENCE(2): Audience.
newRole
Role that the user switches to:
  • CLIENT_ROLE_BROADCASTER(1): Host.
  • CLIENT_ROLE_AUDIENCE(2): Audience.

onClientRoleChangeFailed

Occurs when the user role switch fails in the interactive live streaming.

public void onClientRoleChangeFailed(int reason, int currentRole) {}

In the live broadcasting channel profile, when the local user calls setClientRole [1/2] to switch their user role after joining the channel but the switch fails, the SDK triggers this callback to report the reason for the failure and the current user role.

Parameters

reason
The possible reasons for the switch failure include the following:
  • CLIENT_ROLE_CHANGE_FAILED_TOO_MANY_BROADCASTERS(1): The number of hosts in the channel is already at the upper limit.
    Note: This enumerator is reported only when the support for 128 users is enabled. The maximum number of hosts is based on the actual number of hosts configured when you enable the 128-user feature.
  • CLIENT_ROLE_CHANGE_FAILED_NOT_AUTHORIZED(2): The request is rejected by the Agora server. Agora recommends you prompt the user to try to switch their user role again.
  • CLIENT_ROLE_CHANGE_FAILED_REQUEST_TIME_OUT(3): The request is timed out. Agora recommends you prompt the user to check the network connection and try to switch their user role again.
  • CLIENT_ROLE_CHANGE_FAILED_CONNECTION_FAILED(4): The SDK connection fails. You can use reason reported in the onConnectionStateChanged callback to troubleshoot the failure.
currentRole
Current user role.
  • CLIENT_ROLE_BROADCASTER(1): Host. A host can both send and receive streams.
  • CLIENT_ROLE_AUDIENCE(2): Audience. An audience member can only receive streams.

onConnectionInterrupted

Occurs when the connection between the SDK and the server is interrupted.

public void onConnectionInterrupted() {}
Deprecated:
Use onConnectionStateChanged instead.
The SDK triggers this callback when it loses connection with the server for more than four seconds after the connection is established. After triggering this callback, the SDK tries to reconnect to the server. You can use this callback to implement pop-up reminders. The difference between this callback and onConnectionLost is:
  • The SDK triggers the onConnectionInterrupted callback when it loses connection with the server for more than four seconds after it successfully joins the channel.
  • The SDK triggers the onConnectionLost callback when it loses connection with the server for more than 10 seconds, whether or not it joins the channel.
If the SDK fails to rejoin the channel 20 minutes after being disconnected from Agora's edge server, the SDK stops rejoining the channel.

onConnectionLost

Occurs when the SDK cannot reconnect to Agora's edge server 10 seconds after its connection to the server is interrupted.

public void onConnectionLost() {}

The SDK triggers this callback when it cannot connect to the server 10 seconds after calling the joinChannel [2/2] method, regardless of whether it is in the channel. If the SDK fails to rejoin the channel within 20 minutes after disconnecting, the SDK will stop trying to reconnect.

onConnectionStateChanged

Occurs when the network connection state changes.

public void onConnectionStateChanged(int state, int reason) {}

When the network connection state changes, the SDK triggers this callback and reports the current connection state and the reason for the change.

Parameters

state

The current connection state.

  • CONNECTION_STATE_DISCONNECTED (1): The SDK is disconnected from Agora's edge server.
  • CONNECTION_STATE_CONNECTING (2): The SDK is connecting to Agora's edge server.
  • CONNECTION_STATE_CONNECTED (3): The SDK is connected to Agora's edge server and has joined a channel.
  • CONNECTION_STATE_RECONNECTING (4): The SDK keeps reconnecting to the Agora edge server.
  • CONNECTION_STATE_FAILED 5: The SDK fails to connect to Agora's edge server or join the channel.
reason

The reason for a connection state change.

  • CONNECTION_CHANGED_CONNECTING (0): The SDK is connecting to Agora's edge server.
  • CONNECTION_CHANGED_JOIN_SUCCESS (1): The SDK has joined the channel successfully.
  • CONNECTION_CHANGED_INTERRUPTED (2): The connection between the SDK and Agora's edge server is interrupted.
  • CONNECTION_CHANGED_BANNED_BY_SERVER (3): The connection between the SDK and Agora's edge server is banned by Agora's edge server.
  • CONNECTION_CHANGED_JOIN_FAILED (4): The SDK fails to join the channel.
  • CONNECTION_CHANGED_LEAVE_CHANNEL (5): The SDK has left the channel.
  • CONNECTION_CHANGED_INVALID_APP_ID (6): The connection failed because the App ID is not valid. Please rejoin the channel with a valid App ID.
  • CONNECTION_CHANGED_INVALID_CHANNEL_NAME (7): The connection failed because the channel name is not valid. Please rejoin the channel with a valid channel name.
  • CONNECTION_CHANGED_INVALID_TOKEN (8): The connection failed because the token is not valid. Typical reasons include:
    • The App Certificate for the project is enabled in Agora Console, but you do not use a token when joining the channel. If you enable the App Certificate, you must use a token to join the channel.
    • The uid specified when calling joinChannel [1/2] to join the channel is inconsistent with the uid passed in when generating the token.
  • CONNECTION_CHANGED_TOKEN_EXPIRED (9): The token has expired. You need to generate a new token from your server.
  • CONNECTION_CHANGED_REJECTED_BY_SERVER (10): The user is banned by the server.
  • CONNECTION_CHANGED_SETTING_PROXY_SERVER (11): The SDK tries to reconnect after setting a proxy server.
  • CONNECTION_CHANGED_RENEW_TOKEN (12): The connection state changed because the token is renewed.
  • CONNECTION_CHANGED_CLIENT_IP_ADDRESS_CHANGED (13): The IP Address of the SDK client has changed, probably due to a change of the network type, IP address, or network port.
  • CONNECTION_CHANGED_KEEP_ALIVE_TIMEOUT (14): Timeout for the keep-alive of the connection between the SDK and the Agora edge server. The connection state changes to state.
  • CONNECTION_CHANGED_REJOIN_SUCCESS (15): The SDK has rejoined the channel successfully.
  • CONNECTION_CHANGED_LOST (16): The connection between the SDK and the server is lost.
  • CONNECTION_CHANGED_ECHO_TEST (17): The connection state changes due to the echo test.

onEncryptionError

Reports the built-in encryption errors.

public void onEncryptionError(int errorType) {}

When encryption is enabled by calling enableEncryption, the SDK triggers this callback if an error occurs in encryption or decryption on the sender or the receiver side.

Parameters

errorType
Error type.
  • ENCRYPTION_ERROR_INTERNAL_FAILURE(0): Internal reasons.
  • ENCRYPTION_ERROR_DECRYPTION_FAILURE(1): Decryption errors. Ensure that the receiver and the sender use the same encryption mode and key.
  • ENCRYPTION_ERROR_ENCRYPTION_FAILURE(2): Encryption errors.

onError

Reports an error during SDK runtime.

public void onError(int err) {}

This callback indicates that an error (concerning network or media) occurs during SDK runtime. In most cases, the SDK cannot fix the issue and resume running. The SDK requires the application to take action or informs the user about the issue.

Parameters

err
Error code.
  • ERR_OK(0): No error.
  • ERR_FAILED(1): General error with no classified reason. Try calling the method again.
  • ERR_INVALID_ARGUMENT(2): An invalid parameter is used. For example, the specified channel name includes illegal characters. Reset the parameter.
  • ERR_NOT_READY(3): The SDK is not ready. Possible reasons include the following:
    • The initialization of RtcEngine fails. Reinitialize the RtcEngine.
    • No user has joined the channel when the method is called. Please check your code logic.
    • The user has not left the channel when the rate or complain method is called. Please check your code logic.
    • The audio module is disabled. The program is not complete.
  • ERR_NOT_SUPPORTED(4): RtcEngine does not support the request. Possible reasons include the following:
    • The setBeautyEffectOptions method is called on devices running versions earlier than Android 5.0. Check the Android version.
    • The built-in encryption mode is incorrect, or the SDK fails to load the external encryption library. Check the encryption mode setting, or reload the external encryption library.
  • ERR_REFUSED(5): The request is rejected. Possible reasons include the following:
    • The initialization of RtcEngine fails. Reinitialize the RtcEngine.
    • The channel name is set as the empty string "" when joining the channel. Reset the channel name.
    • When the joinChannelEx method is called to join multiple channels, the specified channel name is already in use. Reset the channel name.
  • ERR_BUFFER_TOO_SMALL(6): The buffer size is insufficient to store the returned data.
  • ERR_NOT_INITIALIZED(7): A method is called before the initialization of RtcEngine. Ensure that the RtcEngine object is initialized before using this method.
  • ERR_INVALID_STATE(8): Invalid state.
  • ERR_NO_PERMISSION(9): Permission to access is not granted. Check whether your app has access to the audio and video device.
  • ERR_TIMEDOUT(10): A timeout occurs. Some API calls require the SDK to return the execution result. This error occurs if the SDK takes too long (more than 10 seconds) to return the result.
  • ERR_JOIN_CHANNEL_REJECTED(17): The request to join the channel is rejected. Possible reasons include the following:
    • The user is already in the channel. Agora recommends using the onConnectionStateChanged callback to get whether the user is in the channel. Do not call this method to join the channel unless you receive the CONNECTION_STATE_DISCONNECTED(1) state.
    • After calling startEchoTest [2/2] for the call test, the user tries to join the channel without calling stopEchoTest to end the current test. To join a channel, the call test must be ended by calling stopEchoTest.
  • ERR_LEAVE_CHANNEL_REJECTED(18): Fails to leave the channel. Possible reasons include the following:
    • The user has left the channel before calling the leaveChannel [1/2] method. Stop calling this method to clear this error.
    • The user calls the leaveChannel [1/2] method to leave the channel before joining the channel. In this case, no extra operation is needed.
  • ERR_ALREADY_IN_USE(19): Resources are already in use.
  • ERR_ABORTED(20): The request is abandoned by the SDK, possibly because the request has been sent too frequently.
  • ERR_RESOURCE_LIMITED(22): The SDK fails to allocate resources because your app uses too many system resources or system resources are insufficient.
  • ERR_INVALID_APP_ID(101): The App ID is invalid. Rejoin the channel with a valid App ID.
  • ERR_INVALID_CHANNEL_NAME(102): The channel name is invalid. A possible reason is that the parameter's data type is incorrect. Rejoin the channel with a valid channel name.
  • ERR_NO_SERVER_RESOURCES(103): Fails to get server resources in the specified region. Try another region when initializing RtcEngine.
  • ERR_TOKEN_EXPIRED(109): The current token has expired. Generate a new token on the server and call renewToken to pass the token.
    Deprecated:
    This enumerator is deprecated. Use CONNECTION_CHANGED_TOKEN_EXPIRED(9) in the onConnectionStateChanged callback instead.
  • ERR_INVALID_TOKEN(110): Invalid token Possible reasons are as follows:
    • App Certificate is enabled in Agora Console, but the code still uses App ID for authentication. Once App Certificate is enabled for a project, you must use token-based authentication.
    • The uid used to generate the token is not the same as the uid used to join the channel.
    Deprecated:
    This enumerator is deprecated. Use CONNECTION_CHANGED_INVALID_TOKEN(8) in the onConnectionStateChanged callback instead.
  • ERR_CONNECTION_INTERRUPTED(111): The network connection is interrupted. The SDK triggers this callback when it loses connection with the server for more than four seconds after the connection is established.
  • ERR_CONNECTION_LOST(112): The network connection is lost. Occurs when the SDK cannot reconnect to Agora's edge server 10 seconds after its connection to the server is interrupted.
  • ERR_NOT_IN_CHANNEL(113): The user is not in the channel when calling the sendStreamMessage method.
  • ERR_SIZE_TOO_LARGE(114): The data size exceeds 1 KB when calling the sendStreamMessage method.
  • ERR_BITRATE_LIMIT(115): The data bitrate exceeds 6 KB/s when calling the sendStreamMessage method.
  • ERR_TOO_MANY_DATA_STREAMS(116): More than five data streams are created when calling the createDataStream [2/2] method.
  • ERR_STREAM_MESSAGE_TIMEOUT(117): The data stream transmission times out.
  • ERR_SET_CLIENT_ROLE_NOT_AUTHORIZED(119): Switching roles fails; try rejoining the channel.
  • ERR_DECRYPTION_FAILED(120): Decryption fails. The user might have entered an incorrect password to join the channel. Check the entered password, or tell the user to try rejoining the channel.
  • ERR_INVALID_USER_ID(121): The user ID is invalid.
  • ERR_CLIENT_IS_BANNED_BY_SERVER(123): The user is banned by the server.
  • ERR_ENCRYPTED_STREAM_NOT_ALLOWED_PUBLISH(130): The SDK does not support pushing encrypted streams to CDN.
  • ERR_INVALID_USER_ACCOUNT(134): The user account is invalid, possibly because it contains invalid parameters.
  • ERR_LOAD_MEDIA_ENGINE(1001): The SDK fails to load the media engine.
  • ERR_ADM_GENERAL_ERROR(1005): A general error occurs (no specified reason). Check whether the audio device is already in use by another app, or try rejoining the channel.
  • ERR_ADM_INIT_PLAYOUT(1008): An error occurs when initializing the playback device. Check whether the playback device is already in use by another app, or try rejoining the channel.
  • ERR_ADM_START_PLAYOUT(1009): An error occurs when starting the playback device. Check the playback device.
  • ERR_ADM_STOP_PLAYOUT(1010): An error occurs when stopping the playback device.
  • ERR_ADM_INIT_RECORDING(1011): An error occurs when initializing the recording device. Check the recording device, or try rejoining the channel.
  • ERR_ADM_START_RECORDING(1012): An error occurs when starting the recording device. Check the recording device.
  • ERR_ADM_STOP_RECORDING(1013): An error occurs when stopping the recording device.
  • ERR_VDM_CAMERA_NOT_AUTHORIZED(1501): Permission to access the camera is not granted. Check whether permission to access the camera permission is granted.

onFacePositionChanged

Reports the face detection result of the local user.

public void onFacePositionChanged(
                int imageWidth, int imageHeight, AgoraFacePositionInfo[] faceRectArr) {}
Once you enable face detection by calling enableFaceDetection(true), you can get the following information on the local user in real-time:
  • The width and height of the local video.
  • The position of the human face in the local view.
  • The distance between the human face and the screen.

This value is based on the fitting calculation of the local video size and the position of the human face.

Attention:
  • When it is detected that the face in front of the camera disappears, the callback will be triggered immediately. When no human face is detected, the frequency of this callback to be rtriggered wil be decreased to reduce power consumption on the local device.
  • The SDK stops triggering this callback when a human face is in close proximity to the screen.
  • On Android, the value of distance reported in this callback may be slightly different from the actual distance. Therefore, Agora does not recommend using it for accurate calculation.

Parameters

imageWidth
The width (px) of the video image captured by the local camera.
imageHeight
The height (px) of the video image captured by the local camera.
faceRectArr
For the information of the detected face. See AgoraFacePositionInfo for details. If several faces are detected, this callback reports several AgoraFacePositionInfo arrays. The length of the array can be 0, which means that no human face is detected in front of the camera.

onFirstLocalAudioFramePublished

Occurs when the first audio frame is published.

public void onFirstLocalAudioFramePublished(int elapsed) {}
The SDK triggers this callback under one of the following circumstances:

Parameters

elapsed
Time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback.

onFirstLocalVideoFrame

Occurs when the first local video frame is displayed on the local video view.

public void onFirstLocalVideoFrame(
      Constants.VideoSourceType source, int width, int height, int elapsed) {}

The SDK triggers this callback when the first local video frame is displayed on the local video view.

Parameters

source
The capture type of the custom video source. See VideoSourceType.
width
The width (px) of the first local video frame.
height
The height (px) of the first local video frame.
elapsed
Time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback. If you call startPreview [1/2] before calling joinChannel [2/2], then this parameter is the time elapsed from calling the startPreview [1/2] method until the SDK triggers this callback.

onFirstLocalVideoFramePublished

Occurs when the first video frame is published.

public void onFirstLocalVideoFramePublished(Constants.VideoSourceType source, int elapsed) {}
The SDK triggers this callback under one of the following circumstances:

Parameters

source
The capture type of the custom video source. See VideoSourceType.
elapsed
Time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback.

onFirstRemoteAudioFrame

Occurs when the first audio frame sent by a specified remote user is received.

public void onFirstRemoteAudioFrame(int uid, int elapsed) {
    }
Deprecated:
Use onRemoteAudioStateChanged instead.

Parameters

uid
The ID of the remote user sending the audio frames.
elapsed
The time elapsed (ms) from the local user calling the joinChannel [2/2] method until the SDK triggers this callback.

onFirstRemoteAudioDecoded

Occurs when the SDK decodes the first remote audio frame for playback.

public void onFirstRemoteAudioDecoded(int uid, int elapsed) {
    }
Deprecated:
Use onRemoteAudioStateChanged instead.
The SDK triggers this callback under one of the following circumstances:
  • The remote user joins the channel and sends the audio stream.
  • The remote user stops sending the audio stream and re-sends it after 15 seconds, and the possible reasons include:
    • The remote user leaves the channel.
    • The remote user is offline.
    • The remote user calls muteLocalAudioStream to stop sending the video stream.
    • The remote user calls disableAudio to disable video.

Parameters

uid
The user ID of the remote user.
elapsed
The time elapsed (ms) from the local user calling the joinChannel [2/2] method until the SDK triggers this callback.

onFirstRemoteVideoDecoded

Occurs when the first remote video frame is received and decoded.

public void onFirstRemoteVideoDecoded(int uid, int width, int height, int elapsed) {}
The SDK triggers this callback under one of the following circumstances:
  • The remote user joins the channel and sends the video stream.
  • The remote user stops sending the video stream and re-sends it after 15 seconds. Reasons for such an interruption include:
    • The remote user leaves the channel.
    • The remote user drops offline.
    • The remote user calls muteLocalVideoStream to stop sending the video stream.
    • The remote user calls disableVideo to disable video.

Parameters

uid
The ID of the remote user sending the video stream.
width
The width (px) of the video stream.
height
The height (px) of the video stream.
elapsed
The time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback.

onFirstRemoteVideoFrame

Occurs when the renderer receives the first frame of the remote video.

public void onFirstRemoteVideoFrame(int uid, int width, int height, int elapsed) {}

Parameters

uid
The ID of the remote user sending the video stream.
width
The width (px) of the video stream.
height
The height (px) of the video stream.
elapsed
The time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback.

onJoinChannelSuccess

Occurs when a user joins a channel.

public void onJoinChannelSuccess(String channel, int uid, int elapsed) {}

This callback notifies the application that a user joins a specified channel.

Parameters

channel
The channel name.
uid
The ID of the user who joins the channel.
elapsed
The time elapsed (ms) from the local user calling joinChannel [2/2] until the SDK triggers this callback.

onLastmileQuality

Reports the last-mile network quality of the local user.

public void onLastmileQuality(int quality) {}

This callback reports the last-mile network conditions of the local user before the user joins the channel. Last mile refers to the connection between the local device and Agora's edge server.

Before the user joins the channel, this callback is triggered by the SDK once startLastmileProbeTest is called and reports the last-mile network conditions of the local user.

Parameters

quality
The last-mile network quality.
  • QUALITY_UNKNOWN(0): The quality is unknown.
  • QUALITY_EXCELLENT(1): The quality is excellent.
  • QUALITY_GOOD(2): The network quality seems excellent, but the bitrate can be slightly lower than excellent.
  • QUALITY_POOR(3): Users can feel the communication is slightly impaired.
  • QUALITY_BAD(4): Users cannot communicate smoothly.
  • QUALITY_VBAD(5): The quality is so bad that users can barely communicate.
  • QUALITY_DOWN(6): The network is down, and users cannot communicate at all.

onLocalAudioStateChanged

Occurs when the local audio stream state changes.

public void onLocalAudioStateChanged(
      LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_ERROR error) {}

When the state of the local audio stream changes (including the state of the audio capture and encoding), the SDK triggers this callback to report the current state. This callback indicates the state of the local audio stream, and allows you to troubleshoot issues when audio exceptions occur.

Attention: When the state is LOCAL_AUDIO_STREAM_STATE_FAILED (3), you can view the error information in the error parameter.

Parameters

state
The state of the local audio.
  • LOCAL_AUDIO_STREAM_STATE_STOPPED(0): The local video is in the initial state.
  • LOCAL_AUDIO_STREAM_STATE_RECORDING(1): The local video capturing device starts successfully.
  • LOCAL_AUDIO_STREAM_STATE_ENCODING(2): The first video frame is successfully encoded.
  • LOCAL_AUDIO_STREAM_STATE_FAILED(3): Fails to start the local video.
error
Local audio state error codes.
  • LOCAL_AUDIO_STREAM_ERROR_OK0: The local audio is normal.
  • LOCAL_AUDIO_STREAM_ERROR_FAILURE1: No specified reason for the local audio failure. Remind your users to try to rejoin the channel.
  • LOCAL_AUDIO_STREAM_ERROR_DEVICE_NO_PERMISSION2: No permission to use the local audio device. Remind your users to grant permission.
  • LOCAL_AUDIO_STREAM_ERROR_DEVICE_BUSY3: The microphone is in use. Remind your users to check whether another application occupies the microphone. Local audio capture automatically resumes after the microphone is idle for about five seconds. You can also try to rejoin the channel after the microphone is idle.
  • LOCAL_AUDIO_STREAM_ERROR_RECORD_FAILURE4: The local audio capture failed.
  • LOCAL_AUDIO_STREAM_ERROR_ENCODE_FAILURE5: The local audio encoding fails.
  • LOCAL_AUDIO_STREAM_ERROR_INTERRUPTED8: The local audio capture is interrupted by system calls, Siri, and alarm clocks. Remind your users to end the phone call, Siri, or alarm clock if the local audio capture is required.

onLocalAudioStats

Reports the statistics of the local audio stream.

public void onLocalAudioStats(LocalAudioStats stats) {}

The SDK triggers this callback once every two seconds.

Parameters

stats
Local audio statistics. See LocalAudioStats.

onLocalUserRegistered

Occurs when the local user registers a user account.

public void onLocalUserRegistered(int uid, String userAccount) {}

After the local user successfully calls registerLocalUserAccount to register the user account or calls joinChannelWithUserAccount [2/2] to join a channel, the SDK triggers the callback and informs the local user's UID and User Account.

Parameters

uid
The ID of the local user.
userAccount
The user account of the local user.

onLocalVideoStateChanged

Occurs when the local video stream state changes.

public void onLocalVideoStateChanged(Constants.VideoSourceType source, int state, int error) {
    super.onLocalVideoStateChanged(source, state, error);
    mCallbackObj = new Object[] {source, state, error};
  }

When the state of the local video stream changes (including the state of the video capture and encoding), the SDK triggers this callback to report the current state. This callback indicates the state of the local video stream, including camera capturing and video encoding, and allows you to troubleshoot issues when exceptions occur.

The SDK triggers the onLocalVideoStateChanged callback with the state code of LOCAL_VIDEO_STREAM_STATE_FAILED and error code of LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE in the following situations:
  • The app switches to the background, and the system gets the camera resource.
  • The camera starts normally, but does not output video frames for four consecutive seconds.

When the camera outputs the captured video frames, if the video frames are the same for 15 consecutive frames, the SDK triggers the onLocalVideoStateChanged callback with the state code of LOCAL_VIDEO_STREAM_STATE_CAPTURING and error code of LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE. Note that the video frame duplication detection is only available for video frames with a resolution greater than 200 × 200, a frame rate greater than or equal to 10 fps, and a bitrate less than 20 Kbps.

Attention: For some device models, the SDK does not trigger this callback when the state of the local video changes while the local video capturing device is in use, so you have to make your own timeout judgment.

Parameters

source
The capture type of the custom video source. See VideoSourceType.
state
  • LOCAL_VIDEO_STREAM_STATE_STOPPED(0): The local video is in the initial state.
  • LOCAL_VIDEO_STREAM_STATE_CAPTURING(1): The local video capturing device starts successfully.
  • LOCAL_VIDEO_STREAM_STATE_ENCODING(2): The first video frame is successfully encoded.
  • LOCAL_VIDEO_STREAM_STATE_FAILED(3): Fails to start the local video.
error
  • LOCAL_VIDEO_STREAM_ERROR_OK(0): The local video is normal.
  • LOCAL_VIDEO_STREAM_ERROR_FAILURE(1): No specified reason for the local video failure.
  • LOCAL_VIDEO_STREAM_ERROR_DEVICE_BUSY(3): The local video capturing device is in use. Remind the user to check whether another application occupies the camera.
  • LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE(4): The local video capture failed. Remind the user to check whether the video capture device is working properly, or the camera is occupied by another application, and then try to rejoin the channel.
    • If your app runs in the background on a device running Android 9 or later, you cannot access the camera.
    • If your app runs on a device running Android 6 or later, this error is reported if the camera is occupied by a third-party app and not property released. Once the camera is released, the SDK triggers this callback again, reporting state CAPTURING, and error ERROR_OK.
  • LOCAL_VIDEO_STREAM_ERROR_ENCODE_FAILURE(5): The local video encoding fails.
  • LOCAL_VIDEO_STREAM_ERROR_DEVICE_NOT_FOUND(8): Fails to find a local video capture device. Remind the user to check whether the camera is connected to the device properly or the camera is working properly, and then to rejoin the channel.

onLocalVideoStats

Reports the statistics of the local video stream.

public void onLocalVideoStats(Constants.VideoSourceType source, LocalVideoStats stats) {}

The SDK triggers this callback once every two seconds to report the statistics of the local video stream.

Parameters

source
The capture type of the custom video source. See VideoSourceType.
stats
The statistics of the local video stream. See LocalVideoStats.

onNetworkQuality

Reports the last mile network quality of each user in the channel.

public void onNetworkQuality(int uid, int txQuality, int rxQuality) {}

This callback reports the last mile network conditions of each user in the channel. Last mile refers to the connection between the local device and Agora's edge server.

The SDK triggers this callback once every two seconds. If a channel includes multiple users, the SDK triggers this callback as many times.

Note: txQuality is UNKNOWN when the user is not sending a stream; rxQuality is UNKNOWN when the user is not receiving a stream.

Parameters

uid

The user ID. The network quality of the user with this user ID is reported.

txQuality
Uplink network quality rating of the user in terms of the transmission bit rate, packet loss rate, average RTT (Round-Trip Time) and jitter of the uplink network. This parameter is a quality rating helping you understand how well the current uplink network conditions can support the selected video encoder configuration. For example, a 1000 Kbps uplink network may be adequate for video frames with a resolution of 640 × 480 and a frame rate of 15 fps in the LIVE_BROADCASTING profile, but may be inadequate for resolutions higher than 1280 × 720.
  • QUALITY_UNKNOWN(0): The quality is unknown.
  • QUALITY_EXCELLENT(1): The quality is excellent.
  • QUALITY_GOOD(2): The network quality seems excellent, but the bitrate can be slightly lower than excellent.
  • QUALITY_POOR(3): Users can feel the communication is slightly impaired.
  • QUALITY_BAD(4): Users cannot communicate smoothly.
  • QUALITY_VBAD(5): The quality is so bad that users can barely communicate.
  • QUALITY_DOWN(6): The network is down, and users cannot communicate at all.
rxQuality
Downlink network quality rating of the user in terms of packet loss rate, average RTT, and jitter of the downlink network.
  • QUALITY_UNKNOWN(0): The quality is unknown.
  • QUALITY_EXCELLENT(1): The quality is excellent.
  • QUALITY_GOOD(2): The network quality seems excellent, but the bitrate can be slightly lower than excellent.
  • QUALITY_POOR(3): Users can feel the communication is slightly impaired.
  • QUALITY_BAD(4): Users cannot communicate smoothly.
  • QUALITY_VBAD(5): The quality is so bad that users can barely communicate.
  • QUALITY_DOWN(6): The network is down, and users cannot communicate at all.

onNetworkTypeChanged

Occurs when the local network type changes.

public void onNetworkTypeChanged(int type) {}

This callback occurs when the connection state of the local user changes. You can get the connection state and reason for the state change in this callback. When the network connection is interrupted, this callback indicates whether the interruption is caused by a network type change or poor network conditions.

Parameters

type
Network types:
  • NETWORK_TYPE_UNKNOWN(-1): The network type is unknown.
  • NETWORK_TYPE_DISCONNECTED(0): The SDK disconnects from the network.
  • NETWORK_TYPE_LAN(1): The network type is LAN.
  • NETWORK_TYPE_WIFI(2): The network type is Wi-Fi (including hotspots).
  • NETWORK_TYPE_MOBILE_2G(3) : The network type is mobile 2G.
  • NETWORK_TYPE_MOBILE_3G(4): The network type is mobile 3G.
  • NETWORK_TYPE_MOBILE_4G(5): The network type is mobile 4G.
  • NETWORK_TYPE_MOBILE_5G(6): The network type is mobile 5G.

onPermissionError

Occurs when the SDK cannot get the device permission.

public void onPermissionError(int permission) {}

When the SDK fails to get the device permission, the SDK triggers this callback to report which device permission cannot be got.

Parameters

permission
The type of the device permission.
  • RECORD_AUDIO(0): Permission for the audio capture device.
  • CAMERA(1): Permission for the camera.

onProxyConnected

Reports the proxy connection state.

public void onProxyConnected(
    String channel, int uid, int proxyType, String localProxyIp, int elapsed) {}

You can use this callback to listen for the state of the SDK connecting to a proxy. For example, when a user calls setCloudProxy and joins a channel successfully, the SDK triggers this callback to report the user ID, the proxy type connected, and the time elapsed fromthe user calling joinChannel [1/2] until this callback is triggered.

Parameters

channel
The channel name.
uid
The user ID.
proxyType
The proxy type connected.
  • PROXY_TYPE_NONE_PROXY(0): Reserved for future use.
  • PROXY_TYPE_UDP_CLOUD_PROXY(1): The cloud proxy for the UDP protocol, that is, the Force UDP cloud proxy mode. In this mode, the SDK always transmits data over UDP.
  • PROXY_TYPE_TCP_CLOUD_PROXY(2): The cloud proxy for the TCP (encryption) protocol, that is, the Force TCP cloud proxy mode. In this mode, the SDK always transmits data over TCP/TLS 443.
  • PROXY_TYPE_LOCAL_PROXY(3): Reserved for future use.
  • PROXY_TYPE_TCP_AUTO_FALLBACK(4): Automatic mode. In this mode, the SDK attempts a direct connection to SD-RTN™ and automatically switches to TCP/TLS 443 if the attempt fails.
localProxyIp
Reserved for future use.
elapsed
The time elapsed (ms) from the user calling joinChannel [1/2] until this callback is triggered.

onRejoinChannelSuccess

Occurs when a user rejoins the channel.

public void onRejoinChannelSuccess(String channel, int uid, int elapsed) {}

When a user loses connection with the server because of network problems, the SDK automatically tries to reconnect and triggers this callback upon reconnection.

Parameters

channel
The channel name.
uid
The ID of the user who rejoins the channel.
elapsed
Time elapsed (ms) from the local user calling the joinChannel [1/2] or joinChannel [2/2] method until this callback is triggered.

onRemoteAudioStateChanged

Occurs when the remote audio state changes.

public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed) {}

When the audio state of a remote user (in a voice/video call channel) or host (in a live streaming channel) changes, the SDK triggers this callback to report the current state of the remote audio stream.

Attention: This callback does not work properly when the number of users (in the communication profile) or hosts (in the live streaming channel) in a channel exceeds 17.

Parameters

uid
The ID of the remote user whose audio state changes.
state
Remote audio states.
  • REMOTE_AUDIO_STATE_STOPPED(0): The remote audo is in the initial state. The SDK reports this state in the case of REMOTE_AUDIO_REASON_LOCAL_MUTED, REMOTE_AUDIO_REASON_REMOTE_MUTED or REMOTE_AUDIO_REASON_REMOTE_OFFLINE.
  • REMOTE_AUDIO_STATE_STARTING(1): The first remote audio packet is received.
  • REMOTE_AUDIO_STATE_DECODING(2): The remote audio stream is decoded and plays normally. The SDK reports this state in the case of REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY, REMOTE_AUDIO_REASON_LOCAL_UNMUTED or REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED.
  • REMOTE_AUDIO_STATE_FROZEN(3): The remote audio is frozen. The SDK reports this state in the case of REMOTE_AUDIO_REASON_NETWORK_CONGESTION.
  • REMOTE_AUDIO_STATE_FAILED(4): The remote audio fails to start. The SDK reports this state in the case of REMOTE_VIDEO_STATE_REASON_INTERNAL.
reason
Remote audio state reasons.
  • REMOTE_AUDIO_REASON_INTERNAL(0): The SDK reports this reason when the audio state changes.
  • REMOTE_AUDIO_REASON_NETWORK_CONGESTION(1): Network congestion.
  • REMOTE_AUDIO_REASON_NETWORK_RECOVERY(2): Network recovery.
  • REMOTE_AUDIO_REASON_LOCAL_MUTED(3): The local user stops receiving the remote audio stream or disables the audio module.
  • REMOTE_AUDIO_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote audio stream or enables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_MUTED(5): The remote user stops sending the audio stream or disables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the audio stream or enables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
elapsed
Time elapsed (ms) from the local user calling the joinChannel [2/2] method until the SDK triggers this callback.

onRemoteAudioStats

Reports the statistics of the audio stream sent by each remote users.

public void onRemoteAudioStats(RemoteAudioStats stats) {}

The SDK triggers this callback once every two seconds. If a channel includes multiple users, the SDK triggers this callback as many times.

Parameters

stats
Statistics of the received remote audio stream. See RemoteAudioStats.

onRemoteAudioTransportStats

Reports the transport-layer statistics of each remote audio stream.

public void onRemoteAudioTransportStats(int uid, int delay, int lost, int rxKBitRate) {}
Deprecated:
Please use onRemoteAudioStats instead.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives an audio packet from a remote user. During a call, when the user receives the video packet sent by the remote user/host, the callback is triggered every 2 seconds.

Parameters

uid
The ID of the remote user sending the audio packets.
delay
The network delay (ms) from the sender to the receiver.
lost
The packet loss rate (%) of the audio packet sent from the remote user.
rxKBitRate
The bitrate of the received audio (Kbps).

onRemoteVideoStateChanged

Occurs when the remote video stream state changes.

public void onRemoteVideoStateChanged(int uid, int state, int reason, int elapsed) {}
Attention: This callback does not work properly when the number of users (in the communication profile) or hosts (in the live streaming channel) in a channel exceeds 17.

Parameters

uid
The ID of the remote user whose video state changes.
state
The state of the remote video:
  • REMOTE_VIDEO_STATE_STOPPED(0): The remote video is in the initial state. This status is reported in the case of REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3), REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5), REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8).
  • REMOTE_VIDEO_STATE_STARTING(1): The first remote video packet is received.
  • REMOTE_VIDEO_STATE_PLAYING(2): The remote audio stream is decoded and plays normally. This status is reported in the case of REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2), REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4), REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6) or REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9).
  • REMOTE_VIDEO_STATE_FROZEN(3): The remote video is frozen. This state is reported in the case of REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1).
  • REMOTE_VIDEO_STATE_FAILED(4): The remote video fails to start. The remote video fails to start, probably due to REMOTE_VIDEO_STATE_REASON_INTERNAL(0).
reason
Remote audio state reasons:
  • REMOTE_VIDEO_STATE_REASON_INTERNAL(0): Internal reasons.
  • REMOTE_VIDEO_STATE_REASON_NETWORK_CONGESTION(1): Network congestion.
  • REMOTE_VIDEO_STATE_REASON_NETWORK_RECOVERY(2): Network recovery.
  • REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED(3): The local user stops receiving the remote video stream or disables the video module.
  • REMOTE_VIDEO_STATE_REASON_LOCAL_UNMUTED(4): The local user resumes receiving the remote video stream or enables the video module.
  • REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED(5): The remote user stops sending the video stream or disables the video module.
  • REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED(6): The remote user resumes sending the video stream or enables the video module.
  • REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE(7): The remote user leaves the channel.
  • REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK(8): The remote media stream falls back to the audio-only stream due to poor network conditions.
  • REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY(9): The remote media stream switches back to the video stream after the network conditions improve.
elapsed
Time elapsed (ms) from the local user calling the joinChannel [2/2] method until the SDK triggers this callback.

onRemoteVideoStats

Reports the statistics of the video stream sent by each remote users.

public void onRemoteVideoStats(RemoteVideoStats stats) {}

Reports the statistics of the video stream from the remote users. The SDK triggers this callback once every two seconds for each remote user. If a channel has multiple users/hosts sending video streams, the SDK triggers this callback as many times.

Parameters

stats
Statistics of the remote video stream. For details, see RemoteVideoStats.

onRemoteVideoTransportStats

Reports the transport-layer statistics of each remote video stream.

public void onRemoteVideoTransportStats(int uid, int delay, int lost, int rxKBitRate) {}
Deprecated:
This callback is deprecated; use onRemoteVideoStats instead.

This callback reports the transport-layer statistics, such as the packet loss rate and network time delay, once every two seconds after the local user receives a video packet from a remote user.

During a call, when the user receives the video packet sent by the remote user/host, the callback is triggered every 2 seconds.

Parameters

uid
The ID of the remote user sending the video packets.
delay
The network delay (ms) from the sender to the receiver.
lost
The packet loss rate (%) of the video packet sent from the remote user.
rxKBitRate
The bitrate of the received video (Kbps).

onRequestToken

Occurs when the token expires.

public void onRequestToken() {}

When the token expires during a call, the SDK triggers this callback to remind the app to renew the token.

Once you receive this callback, generate a new token on your app server, and call joinChannel [2/2] to rejoin the channel.

Parameters

onRtcStats

Reports the statistics of the current call.

public void onRtcStats(RtcStats stats) {}

The SDK triggers this callback once every two seconds after the user joins the channel.

Parameters

stats

Statistics of the RTC engine. See RtcStats.

onRtmpStreamingEvent

Reports events during the media push.

public void onRtmpStreamingEvent(String url, int event) {}

Parameters

url
The URL of media push.
event
The event code of media push.
  • RTMP_STREAMING_EVENT_FAILED_LOAD_IMAGE(1): An error occurs when you add a background image or a watermark image in the media push.
  • RTMP_STREAMING_EVENT_URL_ALREADY_IN_USE(2): The streaming URL is already being used for media push. If you want to start new media push, use a new media push URL.
  • RTMP_STREAMING_EVENT_ADVANCED_FEATURE_NOT_SUPPORT(3): The feature is not supported.
  • RTMP_STREAMING_EVENT_REQUEST_TOO_OFTEN(4): Reserved.

onRtmpStreamingStateChanged

Occurs when the media push state changes.

public void onRtmpStreamingStateChanged(String url, int state, int errCode) {}

When the media push state changes, the SDK triggers this callback and reports the URL address and the current state of the media push. This callback indicates the state of the media push. When exceptions occur, you can troubleshoot issues by referring to the detailed error descriptions in the error code parameter.

Parameters

url

The URL address where the state of the media push changes.

state
The current state of the media push.
  • RTMP_STREAM_PUBLISH_STATE_IDLE(0): The media push has not started or has ended.
  • RTMP_STREAM_PUBLISH_STATE_CONNECTING(1): The SDK is connecting to Agora media push server and the CDN server.
  • RTMP_STREAM_PUBLISH_STATE_RUNNING(2): The media push publishes. The SDK successfully publishes streams and returns this state.
  • RTMP_STREAM_PUBLISH_STATE_RECOVERING(3): The media push is recovering. When exceptions occur to the CDN, or the media push is interrupted, the SDK tries to resume the media push and returns this state.
  • RTMP_STREAM_PUBLISH_STATE_FAILURE(4): Media push fails. See the errCode parameter for the detailed error information.You can also try to publish streams again.
  • RTMP_STREAM_PUBLISH_STATE_DISCONNECTING(5): The SDK is disconnecting from the Agora media push server and CDN server. When you call stopRtmpStream to stop the media push normally, the SDK reports the media push state as RTMP_STREAM_PUBLISH_STATE_DISCONNECTING and RTMP_STREAM_PUBLISH_STATE_IDLE in sequence.
errCode
Error codes of the media push.
  • RTMP_STREAM_PUBLISH_ERROR_OK(0): The media push publishes successfully.
  • RTMP_STREAM_PUBLISH_ERROR_INVALID_ARGUMENT(1): Invalid argument used. Please check the parameter setting.
  • RTMP_STREAM_PUBLISH_ERROR_ENCRYPTED_STREAM_NOT_ALLOWED(2): The media push is encrypted and cannot be published.
  • RTMP_STREAM_PUBLISH_ERROR_CONNECTION_TIMEOUT(3): Timeout for the media push. You can try to push the stream again.
  • RTMP_STREAM_PUBLISH_ERROR_INTERNAL_SERVER_ERROR(4): An error occurs in Agora media push server. You can try to publish media streams again.
  • RTMP_STREAM_PUBLISH_ERROR_RTMP_SERVER_ERROR(5): An error occurs in the CDN server.
  • RTMP_STREAM_PUBLISH_ERROR_TOO_OFTEN(6): A reserved parameter.
  • RTMP_STREAM_PUBLISH_ERROR_REACH_LIMIT(7): The host publishes more than 10 URLs. You can stop publishing sreams to unnecessary URLs
  • RTMP_STREAM_PUBLISH_ERROR_NOT_AUTHORIZED(8): The host manipulates other hosts' URLs. For example, the host updates or stops other hosts' streams. Check your app logic.
  • RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND(9): Agora's server fails to find the media stream of media push.
  • RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED(10): The format of the media push URL is not supported. Check whether the URL format is correct.
  • RTMP_STREAM_PUBLISH_ERROR_NOT_BROADCASTER(11): The user role is not host, so the user cannot use the media push function. Check your application code logic.
  • RTMP_STREAM_PUBLISH_ERROR_TRANSCODING_NO_MIX_STREAM(13): The updateRtmpTranscoding or setLiveTranscoding method is called to update the transcoding configuration in a scenario where there is media push without transcoding. Check your application code logic.
  • RTMP_STREAM_PUBLISH_ERROR_NET_DOWN(14): Errors occurred in the host's network.
  • RTMP_STREAM_PUBLISH_ERROR_INVALID_APPID(15): Your App ID does not have permission to use the media push function.
  • RTMP_STREAM_UNPUBLISH_ERROR_OK(100): The media push has been stopped normally. After you call stopRtmpStream to stop the media push, the SDK returns this value.

onSnapshotTaken

Reports the result of taking a video snapshot.

public void onSnapshotTaken(int uid, String filePath, int width, int height, int errCode) {}

After a successful takeSnapshot method call, the SDK triggers this callback to report whether the snapshot is successfully taken, as well as the details for that snapshot.

Parameters

uid
The user ID. A uid of 0 indicates the local user.
filePath
The local path of the snapshot.
width
The width (px) of the snapshot.
height
The height (px) of the snapshot.
errCode
The message that confirms success or gives the reason why the snapshot is not successfully taken:
  • 0: Success.
  • < 0: Failure:
    • -1: The SDK fails to write data to a file or encode a JPEG image.
    • -2: The SDK does not find the video stream of the specified user within one second after the takeSnapshot method call succeeds.
    • -3: Calling the takeSnapshot method too frequently.

onStreamMessage

Occurs when the local user receives the data stream from the remote user.

public void onStreamMessage(int uid, int streamId, byte[] data) {}

The SDK triggers this callback when the local user receives the stream message that the remote user sends by calling the sendStreamMessage method.

Parameters

uid
The ID of the remote user sending the message.
streamId
The stream ID of the received message.
data
received data.

onStreamMessageError

Occurs when the local user does not receive the data stream from the remote user.

public void onStreamMessageError(int uid, int streamId, int error, int missed, int cached) {}

The SDK triggers this callback when the local user fails to receive the stream message that the remote user sends by calling the sendStreamMessage method.

Parameters

uid
The ID of the remote user sending the message.
streamId
The stream ID of the received message.
error
The error code.
missed
The number of lost messages.
cached
Number of incoming cached messages when the data stream is interrupted.

onTokenPrivilegeWillExpire

Occurs when the token expires in 30 seconds.

public void onTokenPrivilegeWillExpire(String token) {}

When the token is about to expire in 30 seconds, the SDK triggers this callback to remind the app to renew the token.

Upon receiving this callback, generate a new token on your server, and call renewToken to pass the new token to the SDK.

Parameters

token
The token that expires in 30 seconds.

onTranscodingUpdated

Occurs when the publisher's transcoding is updated.

public void onTranscodingUpdated() {}

When the LiveTranscoding class in the setLiveTranscoding method updates, the SDK triggers the onTranscodingUpdated callback to report the update information.

Attention: If you call the setLiveTranscoding method to set the LiveTranscoding class for the first time, the SDK does not trigger this callback.

onUplinkNetworkInfoUpdated

Occurs when the uplink network information changes.

public void onUplinkNetworkInfoUpdated(UplinkNetworkInfo info) {}

The SDK triggers this callback when the uplink network information changes.

Attention: This callback only applies to scenarios where you push externally encoded video data in H.264 format to the SDK.

Parameters

info
The uplink network information. See UplinkNetworkInfo.

onUserEnableLocalVideo

Occurs when a specific remote user enables/disables the local video capturing function.

public void onUserEnableLocalVideo(int uid, boolean enabled) {}

The SDK triggers this callback when the remote user resumes or stops capturing the video stream by calling the enableLocalVideo method.

Parameters

uid
The user ID of the remote user.
enabled
Whether the specified remote user enables/disables the local video capturing function:
  • true: Enable. Other users in the channel can see the video of this remote user.
  • false: Disable. Other users in the channel can no longer receive the video stream from this remote user, while this remote user can still receive the video streams from other users.

onUserEnableVideo

Occurs when a remote user enables/disables the video module.

public void onUserEnableVideo(int uid, boolean enabled) {}

Once the video module is disabled, the user can only use a voice call. The user cannot send or receive any video.

The SDK triggers this callback when a remote user enables or disables the video module by calling the enableVideo or disableVideo method.

Parameters

uid
The user ID of the remote user.
enabled
  • true: Enable.
  • false: Disable.

onUserInfoUpdated

Occurs when the SDK gets the user ID and user account of the remote user.

public void onUserInfoUpdated(int uid, UserInfo userInfo) {}

After a remote user joins the channel, the SDK gets the UID and user account of the remote user, caches them in a mapping table object, and triggers this callback on the local client.

Parameters

uid
The user ID of the remote user.
userInfo
The UserInfo object that contains the user ID and user account of the remote user. See UserInfo for details.

onUserJoined

Occurs when a remote user (COMMUNICATION)/ host (LIVE_BROADCASTING) joins the channel.

public void onUserJoined(int uid, int elapsed) {}
  • In a communication channel, this callback indicates that a remote user joins the channel. The SDK also triggers this callback to report the existing users in the channel when a user joins the channel.
  • In a live-broadcast channel, this callback indicates that a host joins the channel. The SDK also triggers this callback to report the existing hosts in the channel when a host joins the channel. Agora recommends limiting the number of hosts to 17.
The SDK triggers this callback under one of the following circumstances:
  • A remote user/host joins the channel by calling the joinChannel [2/2] method.
  • A remote user switches the user role to the host after joining the channel.
  • A remote user/host rejoins the channel after a network interruption.

Parameters

uid
The ID of the user or host who joins the channel.
elapsed
Time delay (ms) from the local user calling joinChannel [2/2] until this callback is triggered.

onUserMuteAudio

Occurs when a remote user (in the communication profile) or a host (in the live streaming profile) stops/resumes sending the audio stream.

public void onUserMuteAudio(int uid, boolean muted) {}

The SDK triggers this callback when the remote user stops or resumes sending the audio stream by calling the muteLocalAudioStream method.

Attention: This callback does not work properly when the number of users (in the communication profile) or hosts (in the live streaming channel) in a channel exceeds 17.

Parameters

uid
The user ID.
muted
Whether the remote user's audio stream is muted/unmuted:
  • true: User's audio stream is muted.
  • false: User's audio stream is unmuted.

onUserMuteVideo

Occurs when a remote user stops/resumes publishing the video stream.

public void onUserMuteVideo(int uid, boolean muted) {}

When a remote user calls muteLocalVideoStream to stop or resume publishing the video stream, the SDK triggers this callback to report the state of the remote user's publishing stream to the local user.

Attention: This callback can be inaccurate when the number of users (in the communication profile) or hosts (in the live streaming profile) in a channel exceeds 17.

Parameters

uid
The user ID of the remote user.
muted
Whether the remote user stops publishing the video stream:
  • true: The remote user stops publishing the video stream.
  • false: The remote user resumes publishing the video stream.

onUserOffline

Occurs when a remote user (in the communication profile)/ host (in the live streaming profile) leaves the channel.

public void onUserOffline(int uid, int reason) {}
There are two reasons for users to become offline:
  • Leave the channel: When a user/host leaves the channel, the user/host sends a goodbye message. When this message is received, the SDK determines that the user/host leaves the channel.
  • Drop offline: When no data packet of the user or host is received for a certain period of time (20 seconds for the communication profile, and more for the live broadcast profile), the SDK assumes that the user/host drops offline. A poor network connection may lead to false detections. It's recommended to use the Agora RTM SDK for reliable offline detection.

Parameters

uid
The ID of the user who leaves the channel or goes offline.
reason
Reasons why a remote user (COMMUNICATION) or a host (LIVE_BROADCASTING) goes offline:
  • USER_OFFLINE_QUIT(0): The user has quit the call. When the user leaves the channel, the user sends a goodbye message. When this message is received, the SDK determines that the user leaves the channel.
  • USER_OFFLINE_DROPPED(1): The SDK timed out and the user dropped offline because it has not received any data package within a certain period of time. A poor network connection may lead to false detection, so we recommend using the RTM SDK for reliable offline detection.
  • USER_OFFLINE_BECOME_AUDIENCE(2): The user switches the user role from a broadcaster to an audience.

onVideoPublishStateChanged

Occurs when the video publishing state changes.

public void onVideoPublishStateChanged(Constants.VideoSourceType source, String channel,
      int oldState, int newState, int elapseSinceLastState) {}

Parameters

channel
The channel name.
source
The capture type of the custom video source. See VideoSourceType.
oldState
For the previous publishing state, see STREAM_PUBLISH_STATE.
newState
For the current publishing state, see STREAM_PUBLISH_STATE.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.

onVideoSizeChanged

Occurs when the video size or rotation of a specified user changes.

public void onVideoSizeChanged(int uid, int width, int height, int rotation) {}

Parameters

uid
The ID of the user whose video size or rotation changes. (The uid for the local user is 0. The video is the local user's video preview).
width
The width (pixels) of the video stream.
height
The height (pixels) of the video stream.
rotation
The rotation information. The value range is [0,360).

onVideoStopped

Occurs when the video stops playing.

public void onVideoStopped() {}
Deprecated:
Use LOCAL_VIDEO_STREAM_STATE_STOPPED(0) in the onLocalVideoStateChanged callback instead.

The application can use this callback to change the configuration of the view (for example, displaying other pictures in the view) after the video stops playing.

onVideoSubscribeStateChanged

Occurs when the video subscribing state changes.

public void onVideoSubscribeStateChanged(
    String channel, int uid, int oldState, int newState, int elapseSinceLastState) {}

Parameters

channel
The channel name.
uid
The ID of the remote user.
oldState
The previous subscription status.
newState
The current subscription status.
elapseSinceLastState
The time elapsed (ms) from the previous state to the current state.