This topic describes the callback and listener APIs of the Android software development kit (SDK).
Contents
AliRtcEngineEventListener: Provides callbacks related to the local user's behavior.
| API | Description | Supported in the versions above |
| onJoinChannelResult | Callback for the result of joining a channel. | 1.1 |
| onLeaveChannelResult | Callback for the result of leaving a channel. | 1.1 |
| onNetworkQualityChanged | Callback for when the network quality changes. | 1.1 |
| onOccurWarning | Callback for warnings. | 1.1 |
| onOccurError | Callback for errors. | 1.1 |
| onFirstPacketSent | Callback for when the first data packet is sent. | 1.1 |
| onFirstPacketReceived | Callback for when the first data packet is received. | 1.13 |
| onConnectionLost | Callback for when the network connection is lost. | 1.14 |
| onTryToReconnect | Callback for when the SDK tries to reconnect to the network. | 1.14 |
| onConnectionRecovery | Callback for when the network connection is recovered. | 1.14 |
| onParticipantStatusNotify | Callback for when the status of a remote user changes. | 1.14 |
| onPerformanceLow | Callback for when the device performance is low. | 1.16 |
| onPerformanceRecovery | Callback for when the device performance recovers. | 1.16 |
| onFirstLocalVideoFrameDrawn | Callback for when the first frame of the local preview is rendered. | 1.17.2 |
| onAudioPlayingStateChanged | Callback for the audio accompaniment playback state. | 1.16.2 |
| onNetworkQualityProbeTest | Callback for the network quality probe test. | 1.16.2 |
| onFirstRemoteVideoFrameDrawn | Callback for when the first frame of a remote video stream is rendered. | 1.16.2 |
| onUserAudioMuted | Callback for notifications that a user has muted or unmuted their audio. | 1.16.3 |
| onUserVideoMuted | Callback for notifications that a user has muted or unmuted their video. | 1.16.3 |
| onMediaRecordEvent | Callback for recording events. | 1.17 |
| onRtcLocalVideoStats | Callback for local video statistics. | 1.17 |
| onRtcRemoteVideoStats | Callback for remote video performance statistics. | 1.17 |
| onPublishChangedNotify | Callback for the stream publishing result. | 1.17.1 |
| onSubscribeChangedNotify | Callback for the subscription result. | 1.17.1 |
| onMediaExtensionMsgReceived | Callback for receiving custom data. | 1.17.1 |
AliRtcEngineNotify: Provides callbacks related to a remote user's behavior.
| API | Description | Supported in the versions above |
| onRemoteUserOnLineNotify | Callback for when a remote user comes online. | 1.1 |
| onRemoteUserOffLineNotify | Callback for when a remote user goes offline. | 1.1 |
| onRemoteTrackAvailableNotify | Callback for when a remote user's audio or video stream changes. | 1.1 |
| onRemoteUserUnPublish | Callback for when a remote user stops publishing a stream. | 1.1 |
| onAliRtcStats | Callback for real-time data. This callback is triggered every 2 seconds. | 1.16 |
| onUpdateRoleNotify | Callback for when a user's role changes. | 1.16 |
| onAudioEffectFinished | Callback for when an audio effect finishes playing. | 1.17.30 |
| onBye | Callback for when the user is removed from the channel by the server or the channel is closed. | 1.1 |
| onParticipantSubscribeNotify | Callback for when a remote user subscribes to a stream. This callback is deprecated and not recommended. | 1.17 |
| onFirstFramereceived | Callback for when the first frame is received. | 1.17 |
| onParticipantUnsubscribeNotify | Callback for when a remote user unsubscribes from a stream. | 1.17 |
| onUserAudioInterruptedBegin | Notification for when a user's audio is interrupted, for example, by an incoming call. | 1.17 |
| onUserAudioInterruptedEnded | Notification for when a user's audio interruption ends. | 1.17 |
| onUserWillResignActive | The remote user's application moves to the background. | 1.17 |
| onUserWillBecomeActive | Callback for when a remote user's application returns to the foreground. | 1.17 |
| onAudioFocusChange | Notification for the result of an audio focus change. The SDK requests audio focus internally. If an external module needs to use the audio focus, it must request the focus again in this callback. | 1.17 |
AliRtcAudioVolumeObserver: Registers a callback for volume levels.
| API | Description | Supported versions |
| AliRtcAudioVolumeObserver | Callback for volume levels. | 1.16.2 |
AliAudioObserver: Callback for audio data.
| API | Description | Supported in the preceding versions |
| onCaptureRawData | Raw audio data. | 1.17 |
| onCaptureData | Audio data of the local published stream. | 1.17 |
| onRenderData | Remote audio data. | 1.17 |
| API | Description | Supported in the versions listed above |
| onLocalVideoSample | Locally captured video data. | 1.17 |
| onRemoteVideoSample | Video data of a subscribed remote stream. | 1.17 |
| API | Description | Supported in the above versions |
| onData | Callback interface for facial recognition. | 1.15 |
| API | Description | Supported in the specified versions |
| onTextureCreate | A texture for the local video stream is created. | 1.15 |
| onTexture | Each video frame is processed. | 1.15 |
| onTextureDestroy | The texture for the local video stream is destroyed. | 1.15 |
Deprecated callback APIs
AliRtcEngineEventListener: Provides callbacks related to the local user's behavior.
| API | Description | Supported in the versions above |
| onPublishResult | Callback for the result of publishing an audio or video stream. | 1.1 |
| onUnpublishResult | Callback for stopping the publishing of an audio and video stream. | 1.1 |
| onSubscribeResult | Callback for a subscription. | 1.1 |
| onUnsubscribeResult | Callback for an unsubscription. | 1.1 |
API details
- onJoinChannelResult: Callback for the result of joining a channel.
void onJoinChannelResult(int result);Parameter Type Description result int 0 indicates that the user successfully joined the channel. A non-zero value indicates failure. - onLeaveChannelResult: Callback for the result of leaving a channel.
void onLeaveChannelResult(int result);Parameter Type Description result int 0 indicates that the user successfully left the channel. A non-zero value indicates failure. - onNetworkQualityChanged: Callback for when the network quality changes.
You can display a notification on the UI when the network quality is poor.
void onNetworkQualityChanged(String uid, AliRtcNetworkQuality upQuality, AliRtcNetworkQuality downQuality);Parameter Type Description downQuality AliRtcNetworkQuality The downlink network quality. upQuality AliRtcNetworkQuality The uplink network quality. uid String The ID of the user whose network quality has changed. An empty UID indicates the local user. A non-empty UID indicates a remote user. - onOccurWarning: Callback for when a warning occurs.
This warning callback can be ignored. It does not affect the normal use of the SDK.
void onOccurWarning(int warn);Parameter Type Description warn int The type of warning. For more information, see the error code table. - onOccurError: Callback for when an error occurs.
If the error parameter is 16908812 or 33620229, call `destroy` to destroy the instance. Then, create a new SDK instance and call `joinChannel` to join the channel.
void onOccurError(int error);Parameter Type Description error int The type of error. For more information, see Error codes. - onFirstPacketSent: Callback for when the first data packet is sent.
public void onFirstPacketSent(String callId, String streamLabel, String trackLabel, int timeCost);Parameter Type Description callId String The remote callId. streamLabel String The stream label. trackLabel String The stream tag. timeCost int The time elapsed in milliseconds (ms). - onFirstPacketReceived: Callback for when the first data packet is received.
void onFirstPacketReceived(String callId, String streamLabel, String trackLabel, int timeCost);Parameter Type Description callId String The remote callId. streamLabel String The stream label. trackLabel String The track label. timeCost int The time elapsed in milliseconds (ms). - onConnectionLost: Callback for when the network connection is lost.
void onConnectionLost(); - onTryToReconnect: Callback for when the SDK tries to reconnect to the network.
void onTryToReconnect(); - onConnectionRecovery: Callback for when the network connection is recovered.
void onConnectionRecovery(); - onParticipantStatusNotify: Callback for when the status of a remote user changes.
void onParticipantStatusNotify(AliStatusInfo[] status_info_list, int count);Parameter Type Description status_info_list AliStatusInfo[] An array of user statuses. count int The length of the array. onPerformanceLow: Callback for when the device performance is low.
void onPerformanceLow();onPerformanceRecovery: Callback for when the device performance recovers.
void onPermormanceRecovery();onFirstLocalVideoFrameDrawn: Callback for when the first frame of the local preview is rendered.
void onFirstLocalVideoFrameDrawn();onAudioPlayingStateChanged: Callback for the playback state of the audio accompaniment.
public void onAudioPlayingStateChanged(AliRtcAudioPlayingStateCode playState, AliRtcAudioPlayingErrorCode errorCode) {}Parameter Type Description playStatus AliRtcAudioPlayingStatus The current playback state. Valid values: - AliRtcAudioPlayingStarted: Playback starts.
- AliRtcAudioPlayingStopped: Playback stops.
- AliRtcAudioPlayingPaused: Playback is paused.
- AliRtcAudioPlayingResumed: Playback resumes.
- AliRtcAudioPlayingEnded: Playback ends.
- AliRtcAudioPlayingBuffering: Buffering.
- AliRtcAudioPlayingBufferingEnd: Buffering ends.
- AliRtcAudioPlayingFailed: Playback fails.
errorCode AliRtcAudioPlayingErrorCode The error code. onNetworkQualityProbeTest: Callback for the result of a network quality probe test.
void onNetworkQualityProbeTest(AliRtcNetworkQuality networkQuality);Parameter Type Description networkQuality AliRtcNetworkQuality The network quality. onFirstRemoteVideoFrameDrawn: Callback for when the first frame of a remote video stream is rendered.
void onFirstRemoteVideoFrameDrawn(String uid, AliRtcVideoTrack videoTrack);Parameter Type Description uid String The user ID. VideoTrack AliRtcVideoTrack The video stream type. onUserAudioMuted: Callback for when a user mutes or unmutes their audio.
void onUserAudioMuted(String uid, boolean mute);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. mute boolean true: muted. false: unmuted. onUserVideoMuted: Callback for when a user mutes or unmutes their video.
void onUserVideoMuted(String uid, boolean mute);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. mute boolean true: Black frames are published. false: The video is published as normal. onMediaRecordEvent: Callback for recording events.
public void onMediaRecordEvent(int result, String filePath);Parameter Type Description result int - 0: Recording starts.
- 1: Recording ends.
- 2: Failed to open the file.
- 3: Failed to write to the file.
filePath String The path where the recording file is stored. onRtcLocalVideoStats: Callback for local video statistics.
public void onRtcLocalVideoStats(AliRTCLocalVideoStats aliRtcStats);Parameter Type Description aliRtcStats AliRTCLocalVideoStats The data of the published video stream. onRtcRemoteVideoStats: Callback for remote video statistics.
public void onRtcRemoteVideoStats(AliRTCRemoteVideoStats aliRtcStats);Parameter Type Description aliRtcStats AliRTCRemoteVideoStats The data of the subscribed video stream. onPublishChangedNotify: Callback for the result of publishing a stream.
public void onPublishChangedNotify(int result, boolean isPublished);Parameter Type Description result int 0 indicates success. Other values indicate failure. isPublished boolean true: The stream is published. false: The stream is unpublished. onSubscribeChangedNotify: Callback for the result of subscribing to a stream.
public void onSubscribeChangedNotify(String uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack);Parameter Type Description uid String The user ID. audioTrack AliRtcAudioTrack The audio stream. videoTrack AliRtcVideoTrack The video stream. - onMediaExtensionMsgReceived: Callback for receiving custom data from a user in the channel.
public void onMediaExtensionMsgReceived(String uid byte[]message) {}Parameter Type Description uid String The user UID. message byte[] The received custom data. - onRemoteUserOnLineNotify: Callback for when a remote user goes online.
void onRemoteUserOnLineNotify(String uid);Parameter Type Description uid String The ID of the remote user. - onRemoteUserOffLineNotify: Callback for when a remote user goes offline.
void onRemoteUserOffLineNotify(String uid);Parameter Type Description uid String The ID of the remote user. - onRemoteTrackAvailableNotify: Callback for when the state of a remote user's audio or video stream changes.
void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack);Parameter Type Description uid String The ID of the remote user. audioTrack AliRtcAudioTrack The audio stream of the remote user after the change. videoTrack AliRtcVideoTrack The video stream of the remote user after the change. onAliRtcStats: Callback for real-time data. This callback is triggered every 2 seconds.
void onAliRtcStats(AliRtcStats stats);Parameter Type Description stats AliRtcStats The real-time data of the user. onUpdateRoleNotify: Callback for when a user's role changes.
void onUpdateRoleNotify(AliRTCSDK_Client_Role old_role , AliRTCSDK_Client_Role new_role);Parameter Type Description old_role AliRTCSDK_Client_Role The role before the change. new_role AliRTCSDK_Client_Role The role after the change. - onAudioEffectFinished: Callback for when an audio effect finishes playing.
public void onAudioEffectFinished(int soundId) {}Parameter Type Description soundId int The ID that the user assigned to the audio effect file. - onBye: Callback for when a user is removed from the channel by the server or when the channel is closed.
void onBye(int code);Parameter Type Description code int The message type. - 1: The user is removed from the channel by the server.
- 2: The channel is closed.
- 3: The user is removed from the channel because the same UID is used to log on from another device.
- onParticipantSubscribeNotify: Callback for when a remote user subscribes to a stream. This callback is deprecated and not recommended.
public void onParticipantSubscribeNotify(AliSubscriberInfo[] subcribeinfoList, int feedCount){}Parameter Type Description subcribeinfoList AliSubscriberInfo[] Information about the remote users who subscribed to the stream. feedCount int Number of subscriptions - onFirstFrameReceived: Callback for when the first frame is received.
public void onFirstFramereceived(String userId, AliRtcVideoTrack videoTrack, AliRtcAudioTrack audioTrack, int timeCost) {}Parameter Type Description userId String The user UID. videoTrack AliRtcVideoTrack The type of the successfully received video stream. audioTrack AliRtcVideoTrack The type of the successfully received audio stream. timeCost int The time elapsed in milliseconds (ms). - onParticipantUnsubscribeNotify: Callback for when a remote user unsubscribes from a stream.
void onParticipantUnsubscribeNotify(AliParticipantInfo[] participantList, int feedCount)Parameter Type Description participantList AliParticipantInfo Information about the remote users who unsubscribed from the stream. feedCount int The number of users who unsubscribed. - onUserAudioInterruptedBegin: Callback for when a user's audio is interrupted, such as when the audio is preempted by an incoming call.
void onUserAudioInterruptedBegin(String uid);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. - onUserAudioInterruptedEnded: Callback for when a user's audio interruption ends.
void onUserAudioInterruptedEnded(String uid);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. - onUserWillResignActive: Callback for when a remote user's application is switched to the background.
void onUserWillResignActive(String uid);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. - onUserWillBecomeActive: Callback for when a remote user's application returns to the foreground.
void onUserWillBecomeActive(String uid);Parameter Type Description uid String The user ID. This is a unique identifier assigned by the AppServer. - onAudioFocusChange: Callback for the result of an audio focus change. The SDK requests audio focus internally. If an external module also needs to use the audio focus, it must request the focus again in this callback.
public void onAudioFocusChange(int focusChange){}Parameter Type Description focusChange int The audio state. Valid values: - AudioManager.AUDIOFOCUS_GAIN: A permanent audio focus gain.
- AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: A transient audio focus gain.
- AudioManager.AUDIOFOCUS_LOSS: A permanent audio focus loss.
- AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: A transient audio focus loss.
- AliRtcAudioVolumeObserver: Registers a callback for volume levels.
void onAudioVolume(List<AliRtcEngine.AliRtcAudioVolume> list, int volume);Parameter Type Description list List<AliRtcEngine.AliRtcAudioVolume> If the UID is 0, it indicates the volume of the local user. If the UID has a value, it indicates the volume of a remote user. volume int The current volume of the remote mixed stream. - onCaptureRawData: Callback for raw audio data.
void onCaptureRawData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec);Parameter Type Description dataPtr long The audio data. numOfSamples int The number of samples. bytesPerSample int The number of bytes per sample. For PCM data, this is typically 16 bits, which is 2 bytes. numOfChannels int The number of sound channels. Valid values: - 1: mono.
- 2: stereo.
sampleRate int The sample rate. samplesPerSec int The number of samples per second for each sound channel. - onCaptureData: Callback for the audio data of the local published stream.
public void onCaptureData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec);Parameter Type Description dataPtr long The audio data. numOfSamples int The number of samples. bytesPerSample int The number of bytes per sample. For PCM data, this is typically 16 bits, which is 2 bytes. numOfChannels int The number of sound channels. Valid values: - 1: mono.
- 2: stereo.
sampleRate int The sample rate. samplesPerSec int The number of samples per second for each sound channel. - onRenderData: Callback for remote audio data.
public void onRenderData(long dataPtr, int numSamples, int bytesPerSample, int numChannels, int sampleRate, int samplesPerSec);Parameter Type Description dataPtr long The audio data. numOfSamples int The number of samples. bytesPerSample int The number of bytes per sample. For PCM data, this is typically 16 bits, which is 2 bytes. numOfChannels int The number of sound channels. Valid values: - 1: mono.
- 2: stereo.
sampleRate int The sample rate. samplesPerSec int The number of samples per second for each sound channel. - onLocalVideoSample: Callback for locally captured video data.
void onLocalVideoSample(AliRtcEngine.AliVideoSourceType videoSourceType, AliRtcEngine.AliVideoSample videoSample);Parameter Type Description videoSourceType AliVideoSourceType The video source. videoSample AliVideoSample The video sample. - onRemoteVideoSample: Callback for the video data of a subscribed remote stream.
void onRemoteVideoSample(String userId, AliRtcEngine.AliVideoSourceType videoSourceType, AliRtcEngine.AliVideoSample videoSample);Parameter Type Description userId String The user ID. videoSourceType AliVideoSourceType The video source. videoSample AliVideoSample The video sample. - onData: Callback interface for facial recognition.
long onData(long dataFrameY, long dataFrameU, long dataFrameV, AliRtcEngine.AliRTCImageFormat aliRTCImageFormat, int width, int height, int strideY, int strideU, int strideV, int rotate, long extraData);Parameter Type Description dataFrameY long A pointer to the Y component. dataFrameU long A pointer to the U component. dataFrameV long A pointer to the V component. This pointer is null for NV12 and NV21. aliRTCImageFormat AliRtcEngine.AliRTCImageFormat The image data format. width int The image width. height int The image height. strideY int The stride of the Y component of the image. strideU int The stride of the U component of the image. strideV int The stride of the V component of the image. rotate int The rotation angle of the image. extraData long An additional field. You can ignore this parameter if it is not customized. - onTextureCreate: Callback for when a texture for the local video stream is created.
void onTextureCreate(String userId, long context);Parameter Type Description userId String The ID of the subscribed user. If retouching is required for the local user, enter an empty string ("") or the local UID. context long A pointer to the OpenGL context EGLContext. - onTexture: Callback for processing each video frame.
int onTexture(String userId, int textureId, int width, int height, int stride, int rotate, long extraData);Parameter Type Description userId String The ID of the subscribed user. If retouching is required for the local user, enter an empty string ("") or the local UID. textureId int The input texture ID of the video stream. width int The width of the video stream texture. height int The height of the video stream texture. stride int The stride of the video stream texture. rotate int The rotation angle of the video stream texture. extraData long The detected face data. Valid values: - If facial recognition is enabled: A pointer to the face structure data returned by the onData callback of AliDetectObserver.
- If facial recognition is disabled: 0.
Return value
Returns the processed texture ID. If retouching is not required, you can return the original texture ID.
- onTextureDestroy: Callback for when the texture for the local video stream is destroyed.
void onTextureDestroy(String userId);Parameter Type Description userId String The ID of the subscribed user. If retouching is required for the local user, enter an empty string ("") or the local UID. - onPublishResult: Callback for the result of publishing an audio or video stream.
void onPublishResult(int result, String publishId);Parameter Type Description result int 0 indicates success. A non-zero value indicates failure. publishId String The stream ID. - onUnpublishResult: Callback for the result of unpublishing an audio or video stream.
void onUnpublishResult(int result);Parameter Type Description result int 0 indicates success. A non-zero value indicates failure. - onSubscribeResult: Callback for the result of subscribing to a stream.
void onSubscribeResult(String uid, int result, AliRtcVideoTrack vt, AliRtcAudioTrack at);Parameter Type Description uid String The user ID. result int 0 indicates success. A non-zero value indicates failure. vt AliRtcVideoTrack The successfully subscribed video stream. at AliRtcAudioTrack The successfully subscribed audio stream. - onUnsubscribeResult: Callback for the result of unsubscribing from a stream.
void onUnsubscribeResult(int result, String userId);Parameter Type Description result int 0 indicates success. A non-zero value indicates failure. userId String The user ID. - onRemoteUserUnPublish: Callback for when a remote user unpublishes a stream.
void onRemoteUserUnPublish(AliRtcEngine rtcEngine, String userId);Parameter Type Description rtcEngine AliRtcEngine The AliRtcEngine instance. userId String The ID of the remote user.