This topic describes the callback and listener interfaces of the Android SDK.

Table of contents

Note The callback method is asynchronous.

AliRtcEngineEventListener: local user behavior callback.

API Description Supported in the above version
onJoinChannelResult Add channel result callback. 1.1
onLeaveChannelResult Leave the channel result callback. 1.1
onNetworkQualityChanged Callback when the network quality changes. 1.1
onOccurWarning Warning callback. 1.1
onOccurError Error callback. 1.1
onFirstPacketSent The callback for successful data sending of the first frame. 1.1
onFirstPacketReceived The callback for successful data reception of the first packet. 1.13
onConnectionLost The network disconnect callback. 1.14
onTryToReconnect Attempt network reconnection callback. 1.14
onConnectionRecovery Callback for successful network reconnection. 1.14
onParticipantStatusNotify Remote user status change callback. 1.14
onPerformanceLow The callback for insufficient performance of the current device. 1.16
onPerformanceRecovery The callback for performance recovery of the current device. 1.16
onFirstLocalVideoFrameDrawn The local preview render gets the first frame callback. 1.17.2
onAudioPlayingStateChanged Accompanying play callback. 1.16.2
onNetworkQualityProbeTest The network quality probe callback. 1.16.2
onFirstRemoteVideoFrameDrawn The callback when the first frame of the remote video stream is rendered. 1.16.2
onUserAudioMuted User muteAudio notification callback. 1.16.3
onUserVideoMuted User muteVideo notification callback. 1.16.3
onMediaRecordEvent Recording event callback. 1.17
onRtcLocalVideoStats The callback for local video statistics. 1.17
onRtcRemoteVideoStats Remote video statistics callback. 1.17
onPublishChangedNotify The callback for the stream ingest result. 1.17.1
onSubscribeChangedNotify The callback for the subscription result. 1.17.1
onMediaExtensionMsgReceived Receive custom data callbacks. 1.17.1

AliRtcEngineNotify: remote user behavior callback.

API Description Supported in the above version
onRemoteUserOnLineNotify Remote user launch callback. 1.1
onRemoteUserOffLineNotify Remote user offline callback. 1.1
onRemoteTrackAvailableNotify Callback when the audio and video streams of remote users change. 1.1
onRemoteUserUnPublish The callback when the remote user stops publishing. 1.1
onAliRtcStats Real-time data callback (triggered once in 2 seconds). 1.16
onUpdateRoleNotify Callback when the user role changes. 1.16
onAudioEffectFinished The callback for the end of sound playback. 1.17.30
onBye Callback when the server is kicked out or the channel is closed. 1.1
onParticipantSubscribeNotify Callbacks subscribed by remote users (not recommended for expired). 1.17
onFirstFramereceived The callback for the first frame is received. 1.17
onParticipantUnsubscribeNotify The callback for the remote user to cancel the subscription. 1.17
onUserAudioInterruptedBegin The notification that the user audio is interrupted (for example, the audio is preempted when the user makes a call). 1.17
onUserAudioInterruptedEnded The notification of the end of user audio interruption. 1.17
onUserWillResignActive The remote user application switches to the background. 1.17
onUserWillBecomeActive The remote user application returns to the foreground. 1.17
onAudioFocusChange Notification of the result of the change of audio focus (the SDK will request audio focus internally. If the audio focus is used externally again, you need to request it again in this callback). 1.17

AliRtcAudioVolumeObserver: registers the volume callback.

API Description Supported in the above version
AliRtcAudioVolumeObserver The volume callback. 1.16.2

AliAudioObserver: audio data callback.

API Description Supported in the above version
onCaptureRawData Audio raw data. 1.17
onCaptureData Ingest audio data locally. 1.17
onRenderData Remote audio data. 1.17
AliVideoObserver: video data callback.
API Description Supported in the above version
onLocalVideoSample The locally collected video data. 1.17
onRemoteVideoSample Subscribe to remote video data. 1.17
AliDetectObserver: Face Recognition preprocessing interface.
API Description Supported in the above version
onData Face Recognition the callback interface. 1.15
AliTextureObserver: the video stream callback interface.
API Description Supported in the above version
onTextureCreate Local video stream texture creation. 1.15
onTexture Each frame of video stream is processed. 1.15
onTextureDestroy Local video stream texture destruction. 1.15

Discard callback interface directory

AliRtcEngineEventListener: local user behavior callback.

API Description Supported in the above version
onPublishResult Releases the callback for audio and video streams. 1.1
onUnpublishResult The callback that stops publishing audio and video streams. 1.1
onSubscribeResult Subscribe callback. 1.1
onUnsubscribeResult The callback for unsubscribing. 1.1

API operation details

  • onJoinChannelResult: Add channel result callback.
    void onJoinChannelResult(int result);
    Parameter Type Description
    result int 0 indicates that the channel is joined successfully. Non -0 indicates that the channel fails.
  • onLeaveChannelResult: Leave the channel result callback.
    void onLeaveChannelResult(int result);
    Parameter Type Description
    result int 0 indicates the success of leaving the channel. Non -0 indicates the failure.
  • onNetworkQualityChanged: callback when the network quality changes.

    It is recommended to prompt users on the interface when the network quality is poor.

    void onNetworkQualityChanged(String uid, AliRtcNetworkQuality upQuality, AliRtcNetworkQuality downQuality);
    Parameter Type Description
    downQuality AliRtcNetworkQuality The downstream network quality.
    upQuality AliRtcNetworkQuality Upstream network quality.
    uid String The ID of the user whose network quality has changed. If the user ID is empty, it means local, and others means remote.
  • onOccurWarning: a warning callback.

    Currently, the warning callback can be ignored and will not affect normal use.

    void onOccurWarning(int warn);
    Parameter Type Description
    warn int The type of the warning. For more information, see Error codes.
  • onOccurError: the error callback.

    If the parameter error is 16908812 or 33620229, you need to call destroy to destroy the instance, recreate the SDK instance, and then call joinChannel to join the channel.

    void onOccurError(int error);
    Parameter Type Description
    error int The type of the error that occurred. For more information, see Error codes.
  • onFirstPacketSent: The callback for the first frame data being sent successfully.
    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 label of the stream.
    timeCost int The duration. Unit: ms.
  • onFirstPacketReceived: 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 label of the stream.
    timeCost int The duration. Unit: ms.
  • onConnectionLost: network disconnection callback.
    void onConnectionLost();
  • onTryToReconnect: Attempt the network reconnection callback.
    void onTryToReconnect();
  • onConnectionRecovery: The callback for successful network reconnection.
    void onConnectionRecovery();
  • onParticipantStatusNotify: remote user status change notification.
    void onParticipantStatusNotify(AliStatusInfo[] status_info_list, int count);
    Parameter Type Description
    status_info_list AliStatusInfo[] An array of user states.
    count int The length of the array.
  • onPerformanceLow: the callback for insufficient performance of the current device.

    void onPerformanceLow();
  • onPerformanceRecovery: the callback for performance recovery of the current device.

    void onPermormanceRecovery();
  • onFirstLocalVideoFrameDrawn: local preview rendering gets the first frame callback.

    void onFirstLocalVideoFrameDrawn();
  • onAudioPlayingStateChanged: Accompaniment playback callback.

    public void onAudioPlayingStateChanged(AliRtcAudioPlayingStateCode playState, AliRtcAudioPlayingErrorCode errorCode) {}
    Parameter Type Description
    playStatus AliRtcAudioPlayingStatus The current playback status. Valid values:
    • AliRtcAudioPlayingStarted: The playback starts.
    • AliRtcAudioPlayingStopped: Stop playback.
    • AliRtcAudioPlayingPaused: Pause playback.
    • AliRtcAudioPlayingResumed: The playback is resumed.
    • AliRtcAudioPlayingEnded: Stop playback.
    • AliRtcAudioPlayingBuffering: buffering.
    • AliRtcAudioPlayingBufferingEnd: The buffer ends.
    • AliRtcAudioPlayingFailed: The playback failed.
    errorCode AliRtcAudioPlayingErrorCode The error code returned.
  • onNetworkQualityProbeTest: network quality detection callback.

    void onNetworkQualityProbeTest(AliRtcNetworkQuality networkQuality);
    Parameter Type Description
    networkQuality AliRtcNetworkQuality Network quality.
  • onFirstRemoteVideoFrameDrawn: the callback for the completion of rendering of the first frame of the remote video stream.

     void onFirstRemoteVideoFrameDrawn(String uid, AliRtcVideoTrack videoTrack);
    Parameter Type Description
    uid String The ID of a user.
    VideoTrack AliRtcVideoTrack The type of the video stream.
  • onUserAudioMuted: user muteAudio notifications.

    void onUserAudioMuted(String uid, boolean mute);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
    mute boolean true: muted. false: unmuted.
  • onUserVideoMuted: user muteVideo notifications.

    void onUserVideoMuted(String uid, boolean mute);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
    mute boolean true: indicates that black frames are ingested. false: indicates that streams are ingested normally.
  • onMediaRecordEvent: the callback for recording events.

    public void onMediaRecordEvent(int result, String filePath);
    Parameter Type Description
    result int
    • 0: The recording starts.
    • 1: The recording ends.
    • 2: Failed to open the file.
    • 3: Failed to write the file.
    filePath String The storage path of the recording file.
  • onRtcLocalVideoStats: local video statistics callback.

    public void onRtcLocalVideoStats(AliRTCLocalVideoStats aliRtcStats);
    Parameter Type Description
    aliRtcStats AliRTCLocalVideoStats The video stream data at the publishing end.
  • onRtcRemoteVideoStats: remote video statistics callback.

    public void onRtcRemoteVideoStats(AliRTCRemoteVideoStats aliRtcStats);
    Parameter Type Description
    aliRtcStats AliRTCRemoteVideoStats The video stream data of the subscription end.
  • onPublishChangedNotify: callback for stream ingest results.

    public void onPublishChangedNotify(int result, boolean isPublished);
    Parameter Type Description
    result int Returns 0 to indicate success, and returns others to indicate failure.
    isPublished boolean true indicates that the stream ingest is successful. false indicates that the stream ingest is stopped.
  • onSubscribeChangedNotify: the callback for subscription results.

    public void onSubscribeChangedNotify(String uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack);
    Parameter Type Description
    uid String The ID of the user.
    audioTrack AliRtcAudioTrack The audio stream.
    videoTrack AliRtcVideoTrack The video stream.
  • onMediaExtensionMsgReceived: Receive custom data callback. When a user sends custom data in a room, you can use this callback to receive data.
    public void onMediaExtensionMsgReceived(String uid byte[]message) {}
    Parameter Type Description
    uid String User uid.
    message byte[] The received custom data.
  • onRemoteUserOnLineNotify: remote user online callback.
    void onRemoteUserOnLineNotify(String uid);
    Parameter Type Description
    uid String The ID of the remote user.
  • onRemoteUserOffLineNotify: remote user offline callback.
    void onRemoteUserOffLineNotify(String uid);
    Parameter Type Description
    uid String The ID of the remote user.
  • onRemoteTrackAvailableNotify: callback when the audio and video streams of remote users change.
    void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack, AliRtcVideoTrack videoTrack);
    Parameter Type Description
    uid String The ID of the remote user.
    audioTrack AliRtcAudioTrack The audio stream after the remote user changes.
    videoTrack AliRtcVideoTrack The video stream after the remote user changes.
  • onAliRtcStats: real-time data callback (triggered once in 2 seconds).

    void onAliRtcStats(AliRtcStats stats);
    Parameter Type Description
    stats AliRtcStats User real-time data.
  • onUpdateRoleNotify: callback when the user 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: the callback for the end of sound playback.
    public void onAudioEffectFinished(int soundId) {}
    Parameter Type Description
    soundId int The ID assigned by the user to the sound effect file.
  • onBye: callback when the server is kicked out or the channel is closed.
    void onBye(int code);
    Parameter Type Description
    code int The type of the message.
    • 1: kicked out by the server.
    • 2: The channel is closed.
    • 3: The same user ID is logged on to another end and kicked out by the server.
  • onParticipantSubscribeNotify: the callback subscribed by the remote user (not recommended for expired).
    public void onParticipantSubscribeNotify(AliSubscriberInfo[] subcribeinfoList, int feedCount){}
    Parameter Type Description
    subcribeinfoList AliSubscriberInfo[] The information about the users who participate in the subscription at the remote end.
    feedCount int The number of subscriptions.
  • onFirstFramereceived: The callback for the first frame is received.
    public void onFirstFramereceived(String userId, AliRtcVideoTrack videoTrack, AliRtcAudioTrack audioTrack, int timeCost) {}
    Parameter Type Description
    userId String The UID of the Alibaba Cloud account.
    videoTrack AliRtcVideoTrack The type of the received video stream.
    audioTrack AliRtcVideoTrack The type of audio stream that was successfully received.
    timeCost int The amount of time consumed. Unit: milliseconds.
  • onParticipantUnsubscribeNotify: the callback for the remote user to cancel the subscription.
    void onParticipantUnsubscribeNotify(AliParticipantInfo[] participantList, int feedCount)
    Parameter Type Description
    participantList AliParticipantInfo The information about the user who unsubscribes from the remote end.
    feedCount int The number of users who canceled the subscription.
  • onUserAudioInterruptedBegin: the notification that the user audio is interrupted (for example, the audio is preempted when the user makes a call).
    void onUserAudioInterruptedBegin(String uid);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
  • onUserAudioInterruptedEnded: the notification that the user audio interruption ends.
    void onUserAudioInterruptedEnded(String uid);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
  • onUserWillResignActive: The remote user application switches to the background.
    void onUserWillResignActive(String uid);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
  • onUserWillBecomeActive: The remote user application returns to the foreground.
    void onUserWillBecomeActive(String uid);
    Parameter Type Description
    uid String User ID, a unique identifier assigned from the AppServer.
  • onAudioFocusChange: Notification of the result of the audio focus change (The SDK internally requests the audio focus. If the external audio focus is used again, you need to request it again in this callback).
    public void onAudioFocusChange(int focusChange){}
    Parameter Type Description
    focusChange int The audio status. Valid values:
    • AudioManager.AUDIOFOCUS_GAIN: Long-term audio focus acquisition.
    • AudioManager.AUDIOFOCUS_GAIN_TRANSIENT: temporary audio focus acquisition.
    • AudioManager.AUDIOFOCUS_LOSS: Long-term audio focus loss.
    • AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: Temporary audio focus loss.
  • AliRtcAudioVolumeObserver: registers the volume callback.
    void onAudioVolume(List<AliRtcEngine.AliRtcAudioVolume> list, int volume);
    Parameter Type Description
    list List<AliRtcEngine.AliRtcAudioVolume> A value of 0 for uid indicates the local volume. A value for uid indicates the volume of a remote user.
    volume int The current remote mixing volume.
  • onCaptureRawData: 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 sampling points.
    bytesPerSample int The number of bytes per sample. For PCM, 16Bit is generally used, that is, two bytes.
    numOfChannels int The number of sound channels. Valid values:
    • 1: mono.
    • 2: two channels.
    sampleRate int The sampling rate.
    samplesPerSec int The number of samples per second per channel.
  • onCaptureData: Ingest audio data locally.
    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 sampling points.
    bytesPerSample int The number of bytes per sample. For PCM, 16Bit is generally used, that is, two bytes.
    numOfChannels int The number of sound channels. Valid values:
    • 1: mono.
    • 2: two channels.
    sampleRate int The sampling rate.
    samplesPerSec int The number of samples per second per channel.
  • onRenderData: 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 sampling points.
    bytesPerSample int The number of bytes per sample. For PCM, 16Bit is generally used, that is, two bytes.
    numOfChannels int The number of sound channels. Valid values:
    • 1: mono.
    • 2: two channels.
    sampleRate int The sampling rate.
    samplesPerSec int The number of samples per second per channel.
  • onLocalVideoSample: locally collected video data.
    void onLocalVideoSample(AliRtcEngine.AliVideoSourceType videoSourceType, AliRtcEngine.AliVideoSample videoSample);
    Parameter Type Description
    videoSourceType AliVideoSourceType The video source.
    videoSample AliVideoSample The video sample.
  • onRemoteVideoSample: Subscribe to remote video data.
    void onRemoteVideoSample(String userId, AliRtcEngine.AliVideoSourceType videoSourceType, AliRtcEngine.AliVideoSample videoSample);
    Parameter Type Description
    userId String The ID of the user.
    videoSourceType AliVideoSourceType The video source.
    videoSample AliVideoSample The video sample.
  • onData: Face Recognition callback interface.
    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 Y component pointer.
    dataFrameU long U component pointer.
    dataFrameV long V component pointer, NV12 and NV21 This pointer is null.
    aliRTCImageFormat AliRtcEngine.AliRTCImageFormat The image data format.
    width int The width of the image.
    height int The height of the image.
    strideY int The Y-component stride of the image.
    strideU int The image U component stride.
    strideV int The image V component stride.
    rotate int Image rotation angle.
    extraData long Additional fields (non-customized and negligible).
  • onTextureCreate: local video stream texture creation.
    void onTextureCreate(String userId, long context);
    Parameter Type Description
    userId String The ID of the subscribed user. Generally, local beautification is required. You can enter an empty string ("") or local uid.
    context long The context EGLContext pointer for the opengl.
  • onTexture: processes each video stream.
    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. Generally, local beautification is required. You can enter an empty string ("") or local uid.
    textureId int The input texture Id of the video stream texture.
    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 Rotate angle of the video stream texture.
    extraData long The detected face data. Valid values:
    • When Face Recognition: A pointer to the face structure data returned for the onData of the AliDetectObserver.
    • If there is no Face Recognition: 0.

    Return result

    Return the texture Id after processing. If you do not need to beautify, return the texture Id before processing.

  • onTextureDestroy: The texture of the local video stream is destroyed.
    void onTextureDestroy(String userId);
    Parameter Type Description
    userId String The ID of the subscribed user. Generally, local beautification is required. You can enter an empty string ("") or local uid.
  • onPublishResult: the callback for releasing audio and video streams.
    void onPublishResult(int result, String publishId);
    Parameter Type Description
    result int 0 indicates that the publication is successful, and non -0 indicates that the publication is failed.
    publishId String The ID of the live stream.
  • onUnpublishResult: the callback that stops publishing audio and video streams.
    void onUnpublishResult(int result);
    Parameter Type Description
    result int A value of 0 indicates that the release was stopped. A value of 0 indicates that the release was successful. A value of 0 indicates that the release failed.
  • onSubscribeResult: subscription callback.
    void onSubscribeResult(String uid, int result, AliRtcVideoTrack vt, AliRtcAudioTrack at);
    Parameter Type Description
    uid String The ID of the user.
    result int 0 indicates that the subscription is successful. A non -0 indicates that the subscription is successful.
    vt AliRtcVideoTrack Subscribe to a successful video stream.
    at AliRtcAudioTrack Subscribe to a successful audio stream.
  • onUnsubscribeResult: cancel the subscription callback.
    void onUnsubscribeResult(int result, String userId);
    Parameter Type Description
    result int 0 indicates that the subscription is canceled. A non -0 indicates that the subscription fails.
    userId String The ID of the user.
  • onRemoteUserUnPublish: Callback when the remote user stops publishing.
    void onRemoteUserUnPublish(AliRtcEngine rtcEngine, String userId);
    Parameter Type Description
    rtcEngine AliRtcEngine AliRtcEngine instance.
    userId String The ID of the remote user.