This topic describes the details of the API for the ApsaraVideo Real-time Communication SDK for Android.
Contents
Basic interfaces
API | Description |
Creates an AliRtcEngine instance. You must call this method in the main thread. Only one primary instance is allowed. | |
You can create an AliRtcEngine instance using the singleton pattern. | |
Destroys an AliRtcEngine instance. | |
Destroys an AliRtcEngine instance. | |
Specifies whether to enable HTML5 compatibility mode. | |
Check whether the current version is compatible with HTML5. | |
Sets a listener to receive callback events for local user actions. | |
Sets a listener to receive notification events for remote user actions. | |
Queries the current SDK version. |
Channel-related methods
API | Description |
Sets the channel mode. | |
Sets the audio encoding and scenario modes. | |
Queries whether audio-only mode is enabled. | |
Enables audio-only mode or audio-video mode. | |
Joins a channel. | |
Joins a channel. | |
Joins a channel. | |
Leaves a channel. | |
Checks whether you are in a channel. | |
Specifies the user role. | |
Queries the user role. | |
Refreshes authentication information. | |
Refreshes authentication information. |
Publishing and subscription-related methods
API | Description |
Stops or resumes publishing local video streams, which is enabled by default. | |
Queries whether the audio track is being published. | |
Specifies whether to subscribe to the audio tracks of remote users by default. By default, all remote audio tracks are subscribed to. We recommend that you call this method before joining a channel. | |
Subscribes to or stops subscribing to the audio track of a specific remote user. | |
Subscribes to or stops subscribing to the audio tracks of all remote users. | |
Specifies whether to publish the local video track. The SDK publishes it by default. | |
Queries whether the video track is being published. | |
Specifies whether to subscribe to the video tracks of remote users by default. By default, all remote video tracks are subscribed to. We recommend that you call this method before joining a channel. | |
Subscribes to or stops subscribing to a specified remote video track. | |
You can stop or resume accepting all remote video streams. | |
Subscribes to or stops subscribing to the media stream of a specific remote user. We recommend that you call this method when both audio and video tracks are available and need to be controlled. | |
This API operation stops or resumes the media stream of a specific remote user. We recommend using it when you need to control both audio and video. | |
Stop or resume the media stream for a specific remote user across channels. | |
Subscribes to or stops subscribing to the streams of all users across channels. | |
Adjusts the playback volume of ingested audio streams. |
Methods related to audio device management
API | Description |
Specifies whether to stop publishing local audio. | |
Specifies whether to stop playing the audio track of a specific remote user. | |
Stops or resumes all remote audio playback. | |
Starts audio capture. | |
Starts audio capture. | |
Stops audio capture. | |
Sets the default audio output device. | |
Sets the audio output device to the earpiece or speaker. | |
Queries whether the current audio output device is the earpiece or speaker. | |
Enables volume detection. | |
Enables in-ear monitoring. | |
Sets the in-ear monitoring volume. | |
Starts the audio playback device. | |
Stops the audio playback device. | |
Sets the local playback volume. | |
Sets the recording volume. | |
Plays an audio file. | |
Stops playing an audio file. | |
Starts audio capture device testing before a session begins. | |
You can disable audio capture detection. |
Methods related to voice change and reverberation
API | Description |
Sets the voice change mode. | |
Set the pitch adjustment parameters. | |
Sets the reverberation mode. | |
Sets the reverberation effect type and specific parameters. | |
Sets a predefined voice beautification effect mode. | |
Sets audio equalizer (EQ) parameters to adjust gain for specific frequency bands. |
Custom Audio Input
API | Description |
Adds an external audio track. | |
Imports external audio data. | |
Sets the volume for stream ingest of external audio. | |
Queries the volume for stream ingest of external audio. | |
Sets the playback volume of external audio. | |
Queries the playback volume of external audio. | |
Removes an external audio track. |
Music accompaniment
API | Description |
Queries audio file information. | |
Starts music accompaniment mixing. | |
Stops music accompaniment mixing. | |
Sets the accompaniment volume, including local playback and stream ingest volumes. | |
Sets the accompaniment stream ingest volume. | |
Queries the accompaniment stream ingest volume. | |
Sets the local playback volume of accompaniment. | |
Queries the local playback volume of accompaniment. | |
Pauses music accompaniment mixing. | |
Resumes music accompaniment mixing. | |
Queries the duration of the accompaniment file, in milliseconds. | |
Queries the playback progress of the accompaniment file, in milliseconds. | |
Sets the playback position of the accompaniment file. |
Sound effects
API | Description |
Preloads a sound effect. | |
Removes a preloaded sound effect. | |
Starts playback of a sound effect. | |
Stops playback of a sound effect. | |
Stops playback of all sound effects. | |
Pauses a sound effect. | |
Pauses all sound effects. | |
Resumes playback of a specified sound effect. | |
You can recover all sound effect files. | |
Sets the volume for mixing sound effects into stream ingest. | |
Queries the volume for mixing sound effects into stream ingest. | |
Sets the volume for mixing all sound effects into stream ingest. | |
Sets the local playback volume of a sound effect. | |
Queries the local playback volume of a sound effect. | |
Sets the local playback volume of all sound effects. |
Media file recording
API | Feature Description |
Records audio and video files (AAC, WAV, MP4). | |
Stops recording audio and video files. |
Methods related to video device management
API | Description |
Creates a SurfaceView rendering view. | |
Sets the rendering view and drawing parameters for local preview. | |
Sets the rendering view and drawing parameters for the video track of a remote user. | |
Sets camera capture preferences. | |
Disables or re-enables local video capture. | |
Specifies whether to stop publishing the local video track. | |
Checks whether the camera is turned on. | |
Sets video encoding properties. | |
Sets video decoding properties. | |
Switches between front and rear cameras. By default, the front camera is used. | |
Queries the current camera direction. | |
Starts local preview. | |
Stops local preview. | |
Sets the camera zoom factor. | |
Queries the maximum supported camera zoom (digital zoom) factor. | |
Queries the current camera zoom factor setting. | |
Sets the camera exposure level. | |
Queries the camera exposure level. | |
Queries the minimum supported camera exposure level. | |
Queries the maximum supported camera exposure level. | |
Turns the camera flash on or off. | |
Checks whether the current device supports manual focus. | |
Sets the manual focus point for the camera. | |
Checks whether the device supports setting an exposure point. | |
Sets the camera exposure point. | |
Checks whether the camera supports automatic face focus. | |
Enables or disables camera face focus. | |
Enables or disables mirroring for preview and stream ingest video. | |
Sets the timing for video capture scaling. |
Configure video data callbacks
API | Feature description |
Registers an object to export video data. | |
Deregisters an object that exports video data. | |
Registers an observer for OpenGL texture data of the local camera track. | |
Deregisters an observer for OpenGL texture data of the local camera track. | |
Takes a screenshot of the video. |
Configure audio data callbacks
API | Feature Description |
Registers an object to export volume data. | |
Deregisters an object that exports volume data. | |
Sets audio callback parameters. | |
Registers an audio data callback. |
Custom video input
API | Description |
Enables an external video source. | |
Imports video data. |
Screen sharing
API | Feature description |
Starts ingesting a screen-sharing stream. | |
You can start sharing the screen and audio stream. Note This method will be phased out. | |
Starts screen sharing. Note This method will be phased out. | |
Stop the screen-sharing stream ingest. | |
Sets the volume of the shared audio stream. | |
You can query whether screen sharing push is set. | |
Sets video encoding properties for screen-sharing streams. |
Live Streaming Bypass Interface
API | Description |
Starts relayed live streaming. | |
Updates relayed live streaming parameters. | |
Stops relayed live streaming. | |
Queries the status of relayed live streaming. |
Network quality testing
API | Description |
Starts network quality testing. | |
Stops network quality testing. |
SEI
API | Description |
Sends SEI messages. | |
Sends SEI messages (extended). |
Other APIs
API | Description |
Sets custom parameters. | |
Queries custom parameters. | |
Sets the path for storing SDK log files. | |
Sets the log level. | |
Sets the device orientation. | |
Requests audio focus. | |
Abandons audio focus. | |
Queries the current network time. | |
Sends a custom message over the data channel. |
AliveEnv interface
API | Feature description |
Sets the global environment. |
Callback events
AliRtcEngineEventListener
API | Feature description |
The callback that is invoked when the network connection status changes. Pay attention to this callback. | |
The callback that is invoked when a local device exception occurs. Pay attention to this callback. | |
The callback that is invoked to return the result of joining a channel. | |
The callback that is invoked to return the result of leaving a channel. | |
The callback that is invoked when the status of stream ingest for an audio track changes. | |
The callback that is invoked when the status of subscription to an audio track changes. | |
The callback that is invoked when the status of stream ingest for a video track changes. | |
The callback that is invoked when the status of subscription to a video track changes. | |
The callback that is invoked when the status of relayed live streaming changes. | |
The callback that is invoked when the status of a relayed live streaming task changes. | |
The callback that is invoked when network quality changes. | |
The callback that is invoked approximately 3 seconds after network quality testing starts. | |
The callback that is invoked approximately 30 seconds after network quality testing starts to provide test results. | |
The callback that is invoked when a screenshot completes. | |
The callback that is invoked when the status of screen-sharing stream ingest changes. | |
The callback that is invoked when the status of subscription to a screen-sharing stream changes. | |
An error notification. | |
The callback for local audio device state changes. |
AliRtcEngineNotify
API | Feature description |
The callback that is invoked when user authentication is about to expire. Authentication expires 30 seconds after you receive this callback. Pay attention to this callback. | |
When the user calls an authenticated API, the server returns a response indicating that the authentication has expired. | |
Offline Notification for a Remote User | |
Online status notifications for remote users. | |
Remote stream ingest notification. | |
A message indicating a server disconnection or the conclusion of a meeting in the channel. | |
Remote user mute notification. | |
Notification that an audio device interruption has started. | |
Notification that an audio device interruption has ended. | |
The callback that is invoked when a remote user sends black video frames. | |
The callback that is invoked when a remote user disables camera capture. | |
The remote user’s application moves to the background. | |
The remote user's application returns to the foreground. | |
The callback that is invoked when local sound effect playback ends. | |
The callback that is invoked when audio file information is available. | |
The callback that is invoked when media extension messages are received. | |
The callback that is invoked when the first remote video frame is rendered. | |
The callback that is invoked when the first local video frame is rendered during preview. | |
The callback that is invoked when the first remote video frame is received. | |
The callback that is invoked when the first video packet is sent. | |
The callback that is invoked when the first audio packet is sent. | |
The callback that is invoked when the first video packet is received. | |
The callback that is invoked when the first audio packet is received. | |
The callback that is invoked when the first remote audio frame is decoded. | |
The callback that is invoked when local music accompaniment playback state changes. | |
The callback that is invoked when a remote user starts playing music accompaniment. | |
The callback that is invoked when a remote user finishes playing music accompaniment. | |
Real-time data callback (triggered every 2 seconds). | |
The callback that is invoked every two seconds to report local video stream publishing statistics. | |
The callback that is invoked every two seconds to report remote video stream subscription statistics. | |
The callback that is invoked every two seconds to report remote audio stream subscription statistics. | |
Publish statistics for the local audio stream every 2 seconds. | |
The callback that is invoked when audio focus changes. This applies only to Android. | |
The callback that is invoked when the audio route changes. This applies only to Android and iOS. | |
The callback that is invoked when a remote user subscribes to the data channel, indicating you can begin sending custom messages. | |
The callback that is invoked when a custom message is received over the data channel. |
AliRtcAudioVolumeObserver
API | Feature Description |
The callback that is invoked to report user volume levels. | |
The callback that is invoked when an active speaker is detected. | |
The callback that is invoked during pre-session audio testing to report volume information. |
AliRtcAudioFrameObserver
API | Feature Description |
The callback that is invoked to report raw captured audio data. | |
The callback that is invoked to report audio data after 3A processing. | |
The callback that is invoked to report audio data being ingested. | |
The callback that is invoked to report playback audio data. | |
The callback that is invoked to report remote audio data being pulled. |
AliRtcDestroyCompletionObserver
API | Feature description |
The callback that is invoked when engine destruction completes. |
AliRtcTextureObserver
API | Feature description |
The callback that is invoked when the OpenGL context is created. | |
The callback that is invoked when the OpenGL texture is updated. | |
The callback that is invoked when the OpenGL context is destroyed. |
AliRtcVideoObserver
API | Feature description |
The callback that is invoked to report locally captured video data. | |
The callback that is invoked to report locally captured video data before encoding. | |
The callback that is invoked to report remote video data being pulled. | |
The preferred output format for video data. | |
Video data output. |
Method details
getInstance[1/2]
You can obtain an AliRtcEngine instance (singleton pattern).
public static AliRtcEngineImpl getInstance(Context context);This method and getInstance[2/2] both create an AliRtcEngine instance. The difference is that
getInstance[2/2]supports additional configuration at instance creation.
When to call
Call this method before calling any other ARTC SDK APIs to create the AliRtcEngine instance.
Limitations
The SDK supports only one AliRtcEngine instance per app.
Parameters
Parameter | Type | Description |
context | Context | The context of the Android activity. |
Return Description
The SDK supports only one AliRtcEngine instance per app.
getInstance[2/2]
Obtain an AliRtcEngine instance using the singleton pattern.
public static AliRtcEngineImpl getInstance(Context context, String extras);This method and
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8f628e533bein" id="72113a6d4d6t8">getInstance[1/2]</a>can both create an AliRtcEngine instance. The difference is that this API supports more configurations when creating the instance.
When to call
Call this method before calling any other ARTC SDK APIs to create the AliRtcEngine instance.
Limitations
The SDK supports only one AliRtcEngine instance per app.
Parameters
Parameter | Type | Description |
context | Context | The context of the Android activity. |
extras | String | Specifies parameters delivered in canary releases. A JSON string configures special SDK features. This parameter can be empty. |
Return value
Returns a singleton instance of the AliRtcEngineImpl class, which is a subclass of AliRtcEngine.
destroy[1/2]
Destroys an AliRtcEngine object.
public abstract void destroy();Destroys the singleton AliRtcEngine object. After calling this method, all internal resources are released. You cannot use any other AliRtcEngine methods or callbacks. To use the engine again, call getInstance to create a new instance.
This method and destroy[2/2] both destroy the engine instance. The difference is that
destroy[2/2]accepts a completion observer.If you plan to recreate an AliRtcEngine instance after destroying it, ensure the destroy operation completes before creating the new instance.
When to call
After completing real-time communication (when you no longer need AliRtcEngine), call this method to release the instance and reduce unnecessary resource usage.
Limitations
To avoid deadlocks, do not call this method from within any SDK callback.
After calling this method, set the engine object to null. For example:
mAliRtcEngine.destroy(); mAliRtcEngine = null;
destroy[2/2]
Destroys an AliRtcEngine object.
public abstract void destroy(AliRtcDestroyCompletionObserver observer);Destroys the singleton AliRtcEngine object. After calling this method, all internal resources are released. You cannot use any other AliRtcEngine methods or callbacks. To use the engine again, call getInstance to create a new instance.
This method is asynchronous. It provides an observer so developers can detect when destruction completes. You must wait for the onDestroyCompletion callback before creating a new instance. Destruction does not complete until the observer callback is triggered.
When to call
We recommend calling this method after completing real-time communication to release the instance.
Limitations
To avoid deadlocks, do not call this method from within any SDK callback.
Related callback
The onDestroyCompletion callback is triggered when the SDK engine object is destroyed, signaling that you may create a new instance.
Parameters
Parameter | Type | Description |
observer | The notification callback for engine destruction completion. Listen to this callback to confirm resource release. |
setH5CompatibleMode
Specifies whether to enable HTML5 compatibility mode.
public static int setH5CompatibleMode(int enable);Parameters
Parameter | Type | Description |
enable | int | Specifies whether to enable HTML5 compatibility mode. Valid values:
|
You cannot modify HTML5 compatibility settings for the current version after creating an AliRtcEngine instance. Call this method before creating the instance.
getH5CompatibleMode
You can check whether it is compatible with H5.
public static int getH5CompatibleMode();Return instructions
1 indicates HTML5 compatibility mode is enabled.
A value of 0 indicates that HTML5 is not supported.
setRtcEngineEventListener
Sets a listener to receive callback events for local user actions.
public abstract void setRtcEngineEventListener(AliRtcEngineEventListener listener);This method sets the listener for events related to the local user, such as join or leave channel results, role changes, audio or video publishing status changes, audio or video subscription status changes, network quality changes and test results, screenshot results, device status and exceptions, and SDK errors. By implementing callback methods in this class, developers can handle lifecycle and state changes for local users in RTC sessions.
All callbacks have default empty implementations. Developers do not need to implement all callbacks—only those relevant to their business logic.
To handle remote user-related callbacks, first-frame or first-packet callbacks, music accompaniment playback status, or authentication callbacks, implement the
AliRtcEngineNotifyclass and callsetRtcEngineNotify.Avoid time-consuming operations in callbacks—for example, calling destroy. This may cause blocking and affect SDK performance.
When to call
Call this method before joining a channel.
Related callbacks
During runtime, the SDK attempts internal retries to recover automatically from anomalies. For unrecoverable errors, the SDK notifies your application through predefined callbacks. Below are key callbacks that require application-level monitoring and response:
Cause | Callbacks and parameters | Solutions | Note |
Authentication failure | The onJoinChannelResult callback returns AliRtcErrJoinBadToken. | When this error occurs, verify that the token is valid. | When you actively call an API, the system returns authentication failure details in the API's callback. |
Network connection failure | The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed. | When this error occurs, rejoin the channel. | The SDK has built-in recovery for short network outages. If disconnection exceeds the preset timeout threshold, the SDK triggers a timeout and disconnects. At this point, check network status and guide the user to rejoin. |
Local device exception | onLocalDeviceException | When this error occurs, verify permissions and hardware status. | RTC services support device detection and diagnostics. When a local device fails, the service notifies the client via callback. If the SDK cannot resolve the issue, the app must intervene to verify device health. |
Parameters
Parameter | Type | Description |
listener | The listener for local user action notifications. |
setRtcEngineNotify
Sets a listener to receive notification events for remote user actions.
public abstract void setRtcEngineNotify(AliRtcEngineNotify listener);This method sets the listener for events related to remote users, such as online or offline notifications, remote user audio or video publishing status, resolution changes, first-frame or first-packet send or receive status for local and remote audio or video, local and remote music accompaniment playback status, mute status, local and remote audio or video stream statistics, SEI reception, custom message reception, and authentication changes. By implementing callback methods in this class, developers can process interaction-related events with remote users.
All callbacks have default empty implementations. Developers do not need to implement all methods—only those relevant to their business logic.
Avoid time-consuming operations in callbacks—for example, calling destroy. This may cause blocking and affect SDK performance.
When to call
Call this method before joining a channel.
Related callbacks
During runtime, the SDK attempts internal retries to recover automatically from anomalies. For unrecoverable errors, the SDK notifies your application through predefined callbacks. Below are key callbacks that require application-level monitoring and response:
Abnormal cause | Callbacks and parameters | Solutions | Note |
Kicked offline | onBye |
| RTC services provide administrators with the ability to remove participants. |
Authentication about to expire | onWillAuthInfoExpire | When this occurs, obtain fresh authentication info on your server, then call refreshAuthInfo to update it. | Authentication expiration occurs in two cases: during API calls or during program execution. Therefore, feedback appears either in the API callback or in a dedicated error callback. |
Authentication expired | onAuthInfoExpired | When this occurs, rejoin the channel. | Authentication expiration occurs in two cases: during API calls or during program execution. Therefore, feedback appears either in the API callback or in a dedicated error callback. |
Parameters
Parameter | Type | Description |
listener | The listener for remote user action notifications, used to receive messages from the engine. |
getSdkVersion
Queries the current SDK version.
public static String getSdkVersion();Return description
The current SDK version number, formatted as a string—for example, "2.5.0.x".
setChannelProfile
Sets the channel mode.
public abstract int setChannelProfile(AliRTCSdkChannelProfile channelProfile);This method sets the channel mode. Two main modes are supported:
Video call mode: All users are streamers, and can both ingest and pull streams.
Interactive stream mode: You must call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="18edf3ea54po4">setClientRole</a>(set the role). Assign the streamer role (AliRTCSdkInteractive) to users who ingest streams in the channel. If users only need to pull streams and do not ingest streams, assign them the viewer role (AliRTCSdkLive). You should configure RTC scenarios in this mode.
We recommend interactive live streaming mode for all RTC scenarios. Set this using
AliRTCSdkInteractiveLive.All users in the same channel must use the same channel profile.
When to call
You can call this method only before joining a channel. You cannot change the mode while in a channel. You can change it after leaving the channel.
Parameters
Parameter | Type | Description |
channelProfile | The channel type. We recommend interactive mode for all RTC scenarios. |
Return value
0 indicates success. Other values indicate failure: 1 means the SDK is uninitialized or already destroyed.
setAudioProfile
Sets the audio encoding and scenario modes.
public abstract int setAudioProfile(AliRtcAudioProfile profile, AliRtcAudioScenario scenario);This method sets the audio encoding and scenario modes. For more information, see Common audio operations and configurations. ARTC SDK defaults to high-quality mode (AliRtcEngineHighQualityMode) and music scenario mode (AliRtcSceneMusicMode). If these defaults do not meet your needs, call this method to configure them.
When to call
You can call this method only before joining a channel. You cannot change it after joining. You can change it after leaving the channel.
Parameters
Parameter | Type | Description |
profile | The audio capture or encoding mode. We recommend high-quality mode (AliRtcEngineHighQualityMode). Note For Web interoperability, set the sample rate to 48 kHz.
| |
scenario | The audio scenario mode. Options include the following:
Note Do not set this to chatroom mode ( |
Return Description
0: success. Less than 0: failure.
isAudioOnly
Checks whether audio-only mode is enabled.
public abstract boolean isAudioOnly();Return Value Description
true: audio-only mode. false: audio-video mode.
setAudioOnlyMode
Enable audio-only mode?
public abstract int setAudioOnlyMode(boolean audioOnly);Parameters
Parameter | Type | Description |
audioOnly | boolean | Specifies whether to use audio-only or audio-video mode. Valid values:
|
Return Information
0 indicates success. Other values indicate failure.
joinChannel[1/3]
You can join the channel (single-entry mode).
public abstract int joinChannel(String token, String channelId, String userId, String userName);This method joins a channel. ARTC organizes users by channel. Users must join a channel to publish or subscribe to audio or video streams. This method, joinChannel[2/3], and joinChannel[3/3] all join channels, but differ in authentication method and user information passed:
This is the single-parameter method. Pass a token-based authentication token. We recommend this for RTC scenarios.
joinChannel[2/3]is a multi-participant join channel interface that requires you to provide a multi-participant join token generated through Token-based authentication, along with the user information used to generate the token.joinChannel[3/3]is for Real-time Conversational AI. Pass a single-parameter token and set thecapabilityProfilebased on the scenario.
By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and push your own audio and video streams to remote users. If you want to cancel the default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="33438e1082mi8">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="243e9483a0suk">setDefaultSubscribeAllRemoteVideoStreams</a> before calling this method to disable the subscription to audio or video streams.
When to call
Call this after creating the engine.
Limitations
After you successfully join a channel, to join another channel while in the current channel, you must first call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="4de6ecc1a4pa2">leaveChannel</a>to leave the current channel and ensure that you receive the<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="70c68b0236xdt">onLeaveChannelResult</a>callback fromAliRtcEngineEventListener. You can then join another channel.This method supports joining only one channel at a time.
Apps using different App IDs cannot interoperate.
Do not call this method when retrying after a failed join.
Related callbacks
After calling this method successfully, the following callbacks are triggered:
When the local client joins a channel, the result is notified through the
AliRtcEngineEventListener<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="712006e223y8z">onJoinChannelResult</a>callback.After you successfully join a channel, remote users trigger the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="40a9273affui1">onRemoteUserOnLineNotify</a>callback.
Parameters
Parameter | Type | Description |
token | String | The authentication token for single-parameter join. |
channelId | String | The channel ID. Must match the token generation value. |
userId | String | The user ID. Must match the token generation value. |
userName | String | The display name of the user—not the user ID. |
Return value
0 indicates success. Non-zero values indicate failure.
joinChannel[2/3]
Join a channel for a multi-participant meeting.
public abstract int joinChannel(AliRtcAuthInfo authInfo, String userName);This method joins a channel. ARTC organizes users by channel. Users must join a channel to publish or subscribe to audio or video streams. This method, joinChannel[1/3], and joinChannel[3/3] all join channels, but differ in authentication method and user information passed:
joinChannel[1/3]uses single-parameter authentication. Pass a token generated by token-based authentication. We recommend this for RTC scenarios.This is the multi-parameter method. Pass a multi-parameter token generated by token-based authentication, along with the user information used to generate the token.
joinChannel[3/3]is for Real-time Conversational AI. Pass a single-parameter token and set thecapabilityProfilebased on the scenario.
By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and push your audio and video streams to remote users. If you want to disable the default subscription, you can call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="474adcf738uxu">setDefaultSubscribeAllRemoteAudioStreams</a>and setDefaultSubscribeAllRemoteVideoStreamsbefore calling this method to disable the subscription to audio or video streams.Before you call the multi-participant meeting API, refer to Token authentication to generate a token.
Limitations
After you join a channel, to switch to a different one, you must first call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="e2525ba6a0k3s">leaveChannel</a>to leave the current channel. You can join a new channel only after you receive the<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="6aefdfedb0op3">onLeaveChannelResult</a>callback fromAliRtcEngineEventListener.This method supports joining only one channel at a time.
Apps using different App IDs cannot interoperate.
Related callbacks
After calling this method successfully, the following callbacks are triggered:
The result of the local client joining a channel is notified through the
AliRtcEngineEventListener<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="fb41cdcfc6acj">onJoinChannelResult</a>callback.After you successfully join the channel, the remote end triggers the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="8e9d69ebe54sr">onRemoteUserOnLineNotify</a>callback.
Parameters
Parameter | Type | Description |
authInfo | Authentication information. The token field must contain a multi-parameter token. Other fields related to token generation must match the token-generation values and cannot be empty. | |
userName | String | The user's display name—not the user ID. Can be empty. |
Return value
0 indicates success. Non-zero values indicate failure.
joinChannel[3/3]
Joins a channel (single-parameter authentication).
public abstract int joinChannel(String token, AliRTCSdkChannelParam channelParam);This method joins a channel. ARTC organizes users by channel. Users must join a channel to publish or subscribe to audio or video streams. This method, joinChannel[1/3], and joinChannel[2/3] all join channels, but differ in authentication method and user information passed:
joinChannel[1/3]is for RTC scenarios. Pass a token-based authentication single-parameter token. We recommend this for RTC scenarios.joinChannel[2/3]uses multi-parameter authentication. Pass a multi-parameter token generated by token-based authentication, along with the user information used to generate the token.This method is for Real-time Conversational AI. Pass a single-parameter token and set the
capabilityProfileparameter. For AI agent conversations, set it toAliCapabilityProfileAiHuman.
If no special configuration is applied, you subscribe by default to audio and video streams from all other users in the channel when joining, and you push your audio and video streams to remote users by default. To disable the default subscription, call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="5423d42229iih">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="0112175788ybe">setDefaultSubscribeAllRemoteVideoStreams</a> before calling this interface to disable subscription to audio or video streams.
Limitations
After successfully joining a channel, to join another channel mid-session, you must first call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="719d580348a95">leaveChannel</a>to leave the current channel and ensure that you receive the<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="d128acfee2fpd">onLeaveChannelResult</a>callback fromAliRtcEngineEventListener, before you can join a channel again.This method supports joining only one channel at a time.
Apps using different App IDs cannot interoperate.
Do not call this method when retrying after a failed join.
Related callbacks
After calling this method successfully, the following callbacks are triggered:
The result of the local client joining a channel is returned through the
AliRtcEngineEventListener's<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="879ae2fa04zjd">onJoinChannelResult</a>callback.After a user successfully joins a channel, the remote client triggers the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="9b5662c5a0nvf">onRemoteUserOnLineNotify</a>callback.
Parameters
Parameter | Type | Description |
token | String | A token for joining a channel as a single participant. |
channelParam | Channel join parameters, mainly for Real-time Conversational AI. Includes:
|
Return description
0 indicates success. Non-zero values indicate failure.
leaveChannel
Leaves a channel. After calling this method, the SDK terminates real-time communication and exits the current channel.
public abstract int leaveChannel();This method is an asynchronous operation. When you call this method successfully, you do not immediately leave the channel because you must wait for the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="7e49937108skj">onLeaveChannelResult</a>callback to be received before you actually leave the channel.After leaveChannel completes, destroy the engine and set the reference to null.
mAliRtcEngine.leaveChannel(); mAliRtcEngine.destroy(); mAliRtcEngine = null;
When to call
Call this after joining a channel and needing to exit.
If you have joined a channel and need to join another, call this first.
Related callbacks
Local client: After you call this method, the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="80f5e30245vfn">onLeaveChannelResult</a>callback is triggered to notify you of the result of leaving the channel.Remote side: After you successfully call this operation, remote users receive a notification through the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#75c700a2376c1" id="69bf5ff199oda">onRemoteUserOffLineNotify</a>callback.
Return description
0 indicates success. Non-zero values indicate failure.
isInCall
Checks whether you are currently in a channel.
public abstract boolean isInCall();Return value
true: in a channel. false: not in a channel.
setClientRole
Sets the user role.
public abstract int setClientRole(AliRTCSdkClientRole clientRole);This method sets the user role as streamer or viewer.
In interactive mode, before joining a channel:
Set role to streamer: The SDK publishes local audio or video by default and receives other streamers' audio or video.
Set role to viewer: The SDK does not publish local audio or video, but receives other streamers' audio or video.
When to call
You can call this before or after joining a channel. Set the role before joining, or switch roles after joining.
Limitations
This method works only in interactive mode—that is, after calling setChannelProfile with AliRTCSdkInteractiveLive.
We recommend explicitly setting the role before joining in interactive mode.
Parameters
Parameter | Type | Description |
clientRole | The user role type. Only effective in interactive mode. |
getCurrentClientRole
Queries the user role.
public abstract AliRTCSdkClientRole getCurrentClientRole();Return description
Returns the current user role.
refreshAuthInfo[1/2]
Refreshes authentication information.
public abstract int refreshAuthInfo(AliRtcAuthInfo authInfo);This method updates authentication information. Tokens expire after a period, preventing connection to the server.
This and refreshAuthInfo[2/2] both update authentication information. This method updates multi-parameter tokens; refreshAuthInfo[2/2] updates single-parameter tokens. For token generation, see token-based authentication.
When to call
Under the following conditions:
When you receive the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e9acb46a25uym" id="7e1510bec7s3s">onAuthInfoWillExpire</a>callback reporting that authentication information is about to expire, we recommend that you regenerate the token on your server-side and then call this method to pass in the new token.If you do not update the token in time, the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="97664f9e46fhp">onAuthInfoExpired</a>callback is triggered to notify you that authentication has expired. You then need to regenerate a token and calljoinChannelto rejoin the channel.
Parameters
Parameter | Type | Description |
authInfo | Authentication information. |
Return Description
0 indicates success. Other values indicate failure.
refreshAuthInfo[2/2]
Refreshes authentication information.
public abstract int refreshAuthInfo(String token);This method updates the token. Tokens expire after a period, preventing connection to the server.
This and refreshAuthInfo[1/2] both update authentication information. This method updates single-parameter tokens; refreshAuthInfo[1/2] updates multi-parameter tokens. For token generation, see token-based authentication.
When to call
We recommend regenerating the token on your server and calling this method under the following conditions:
When the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e9acb46a25uym" id="d708af68eevs9">onAuthInfoWillExpire</a>callback indicates that the authentication information is about to expire.If you do not update the token in time, the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="3fd674e985gl8">onAuthInfoExpired</a>notification is triggered, indicating that authentication has expired. At this point, you must calljoinChannelto rejoin the channel.
Parameters
Parameter | Type | Description |
token | String | The authentication token for single-parameter join. |
Return description
0 indicates success. Other values indicate failure.
publishLocalAudioStream
You can stop or resume publishing the local video stream.
public abstract int publishLocalAudioStream(boolean enable);This method controls whether to publish the locally captured audio track. The SDK publishes audio by default. To disable publishing, call publishLocalAudioStream(false) before joining.
When to call
You can call this before or after joining a channel. Calling before joining modifies the default behavior and takes effect at join time.
Related callbacks
When the local audio stream ingest result changes, the local client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b7e3bb51c2ga9" id="4ced92c3f5hmj">onAudioPublishStateChanged</a> callback to notify you of the latest status of the audio stream ingest, and the remote client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="2b5460d448ga9">onRemoteTrackAvailableNotify</a> callback to notify you that the remote user's audio and video streams have changed.
Parameters
Parameter | Type | Description |
enable | boolean | Specifies whether to publish the audio track. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
isLocalAudioStreamPublished
Queries whether the audio track is published.
public abstract boolean isLocalAudioStreamPublished();Return description
true: audio track is published. false: audio track is not published.
setDefaultSubscribeAllRemoteAudioStreams
Specifies whether to subscribe to remote users' audio tracks by default.
public abstract int setDefaultSubscribeAllRemoteAudioStreams(boolean sub);This method configures whether the system subscribes to remote users' audio tracks by default. This affects subscription behavior for newly joined users. Unless you have specific requirements, we recommend setting this to true.
When to call
You can call this before or after joining a channel.
Before joining:
The SDK subscribes to remote users' audio tracks by default. To change this, call this method before joining.
After joining:
To stop default subscription, call
setDefaultSubscribeAllRemoteAudioStreams(false). New users joining afterward will not be subscribed.To resume subscription for a specific user, call subscribeRemoteAudioStream. For multiple users, call it multiple times.
After stopping default subscription, calling
setDefaultSubscribeAllRemoteAudioStreams(true)resumes subscription only for users who join afterward—not for users who joined during the pause.
Parameters
Parameter | Type | Description |
sub | boolean | Specifies whether to subscribe to remote users' audio tracks by default. Valid values:
|
Return Description
0 indicates success. Other values indicate failure.
subscribeRemoteAudioStream
You can stop or resume pulling audio streams from a specific remote user.
public abstract int subscribeRemoteAudioStream(String uid, boolean sub);This API stops or resumes subscribing to audio streams from a specific remote user. Unless your scenario requires otherwise, we recommend setting it to true.
The SDK subscribes to the audio streams of all remote users by default when you join a meeting. To modify this behavior, you can call <a baseurl="t2309760_v6_1_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="d319c7806ej0h">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before joining the meeting to disable this default configuration.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
sub | boolean | Subscribes to or stops subscribing to the remote user's audio track. Valid values:
|
Return Description
0 indicates success. Other values indicate failure.
subscribeAllRemoteAudioStreams
Specifies whether to subscribe to all remote users' audio tracks.
public abstract int subscribeAllRemoteAudioStreams(boolean sub);This method acts as the master switch for subscribing to remote audio tracks. We recommend setting it to true. Setting it to false causes:
Immediate unsubscription from all remote audio tracks in the current session.
Subsequent new users will not be subscribed either.
It is not possible to individually control the audio stream of a specified user through
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e09342eeb0z4k" id="a56b5f2a3f56k">subscribeRemoteAudioStream</a>.
To resume subscription, call this method again and set sub to true.
The SDK subscribes by default to audio streams from all remote users when you join a meeting. To modify this behavior, call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="5a57cb846fzb2">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join a meeting to disable this default configuration.
Parameters
Parameter | Type | Description |
sub | boolean | Specifies whether to subscribe to all remote users' audio tracks. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
publishLocalVideoStream
Specifies whether to publish the camera track.
public abstract int publishLocalVideoStream(boolean enable);This method controls whether to publish the locally captured video track.
The SDK publishes video by default. To disable publishing, call publishLocalVideoStream(false) before joining.
When to call
You can call this before or after joining a channel.
Calling before joining modifies the default configuration and takes effect at join time.
Related callbacks
When the local audio stream ingest result changes, the local client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#afe6d3c4b1rvg" id="8b70bc353aj68">onVideoPublishStateChanged</a> callback to notify you of the latest audio stream ingest status, and the remote client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="176ee94b46lb7">onRemoteTrackAvailableNotify</a> callback to notify you that the remote users' audio and video streams have changed.
Parameters
Parameter | Type | Description |
enable | boolean | Specifies whether to publish the camera track. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
isLocalVideoStreamPublished
Queries whether the camera track is published.
public abstract boolean isLocalVideoStreamPublished();Return value
true: camera track is published. false: camera track is not published.
setDefaultSubscribeAllRemoteVideoStreams
Specifies whether to subscribe to remote users' video tracks by default.
public abstract int setDefaultSubscribeAllRemoteVideoStreams(boolean sub);This method specifies whether to subscribe to remote users' video tracks by default. The SDK subscribes by default.
When to call
You can call this before or after joining a channel. If you call setDefaultSubscribeAllRemoteVideoStreams(false) after joining, you will not receive video tracks from users who join afterward.
After stopping video subscription, to resume, call subscribeRemoteVideoStream and specify the remote user ID you want to receive. To resume for multiple users, call subscribeRemoteVideoStream multiple times. setDefaultSubscribeAllRemoteVideoStreams(true) only resumes subscription for users who join afterward.
This method specifies whether to subscribe to remote users' video tracks by default.
The SDK subscribes to remote users' audio or video tracks by default when joining a channel. To change this behavior, call this method before joining.
Parameters
Parameter | Type | Description |
sub | boolean | Specifies whether to subscribe to video tracks by default. Valid values:
|
Return value
0 indicates success. Other values indicate failure.
subscribeRemoteVideoStream
Subscribes to or stops subscribing to a specified remote video track.
public abstract int subscribeRemoteVideoStream(String uid, AliRtcVideoTrack track, boolean sub);Subscribes to or unsubscribes from a specific user's video stream.
By default, the SDK subscribes to the video streams of all remote users when you join a meeting. If you want to modify this behavior, you can call <a baseurl="t2309760_v6_1_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="2a6fd8903ce5s">setDefaultSubscribeAllRemoteVideoStreams</a>(false) before joining the meeting to disable this default configuration.
When to call
You can call this before or after joining a channel.
Parameters
Parameter | Type | Description |
uid | String | User UID. |
track | The video track type. | |
sub | boolean | Whether to receive the specified user's video stream.
|
Return Description
0: successful.
Non-zero: failed.
subscribeAllRemoteVideoStreams
Subscribes to or stops subscribing to all remote video streams.
public abstract int subscribeAllRemoteVideoStreams(boolean sub);This method acts as the master switch for subscribing to remote video streams. Setting it to false causes:
Immediate unsubscription from all remote video streams in the current session.
New users who join later will not subscribe either, even if you set
setDefaultSubscribeAllRemoteVideoStreams(true) to subscribe by default.You cannot use
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b738a1b498bc1" id="19b0cea8593i5">subscribeRemoteVideoStream</a>to individually control the video stream of a specified user.
To resume subscription, call this method again and set sub to true.
The SDK subscribes to all remote users' video streams by default when joining a channel. To change this, call setDefaultSubscribeAllRemoteVideosStreams(false) before joining.
Parameters
Parameter | Type | Description |
sub | boolean | Subscribes to or stops subscribing to all remote video streams. Valid values:
|
Return Description
0 indicates success. Other values indicate failure.
subscribeRemoteMediaStream[1/2]
You can stop or resume the media stream from a specific remote user.
public abstract int subscribeRemoteMediaStream(String uid, AliRtcVideoTrack videoTrack, boolean subVideo, boolean subAudio);This method combines subscription to remote audio and video streams.
In this method, AliRtcVideoTrackNo is invalid for AliRtcVideoTrack. Setting it has no effect.
Related methods
Compared with <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#4cec275051vr6" id="faff82a053mev">subscribeRemoteMediaStream[2/2]</a>, this interface uses two Boolean parameters—subVideo and subAudio—to determine whether to subscribe to remote audio and video streams, and videoTrack controls which video stream to pull.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
videoTrack | The type of the video stream. | |
subVideo | boolean | Subscribes to or stops subscribing to the remote user's video stream. Valid values:
|
subAudio | boolean | Subscribes to or stops subscribing to the remote user's audio stream. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
subscribeRemoteMediaStream[2/2]
Subscribes to or stops subscribing to audio and video streams of a remote user.
public abstract int subscribeRemoteMediaStream(String uid, AliRtcVideoTrack videoTrack, AliRtcAudioTrack audioTrack) ;This method combines subscription to remote audio and video streams.
Related methods
Compared with subscribeRemoteMediaStream[1/2], this interface uses the videoTrack and audioTrack parameters to specify the media streams you want to subscribe to in a single interface call, for example:
To subscribe to camera and microphone streams, set videoTrack and audioTrack to
AliRtcVideoTrackCameraandAliRtcAudioTrackMic, respectively.To unsubscribe from the camera stream but keep the microphone, set videoTrack and audioTrack to
AliRtcVideoTrackNoandAliRtcAudioTrackMic, respectively.To unsubscribe from both, set videoTrack and audioTrack to
AliRtcVideoTrackNoandAliRtcAudioTrackNo, respectively.To subscribe to both camera and screen-sharing streams, set videoTrack to
AliRtcVideoTrackBoth. Audio works similarly.
Parameters
Parameter | Type | Description |
uid | String | The user ID—the unique identifier assigned by your app server. |
videoTrack | The video track type. | |
audioTrack | The audio track type. |
Return description
0: successful.
<0: failed.
subscribeRemoteDestChannelStream
Subscribes to or stops subscribing to a specific user's stream across channels.
public abstract int subscribeRemoteDestChannelStream(String channelId, String uid, AliRtcVideoTrack track, boolean sub_audio, boolean sub);Parameters
Parameter | Type | Description |
channelId | String | The remote channel ID. |
uid | String | The remote user ID. |
track | The video stream to subscribe to. | |
sub_audio | boolean | Subscribes to or stops subscribing to the remote user's audio stream. Valid values:
|
sub | boolean | Subscribes to or stops subscribing to the remote user's stream across channels. |
Return Description
0 indicates success. Other values indicate failure.
subscribeRemoteDestChannelAllStream
Subscribes to or stops subscribing to all users' streams across channels.
public abstract int subscribeRemoteDestChannelAllStream(String channelId, AliRtcVideoTrack track, boolean sub_audio, boolean sub);Parameters
Parameter | Type | Description |
channelId | String | The remote destination channel ID. |
videoTrack | The video stream type to subscribe to. | |
sub_audio | boolean | Whether to subscribe to the remote user's audio stream.
|
sub | boolean | You can stop or resume cross-channel subscription for specified user streams.
|
Return description
0: successful.
Non-zero: failed.
setRemoteAudioVolume
Adjusts playback volume for ingested audio streams.
public abstract int setRemoteAudioVolume(String uid, int volume);Use this method to adjust the playback volume of a specific user's audio stream on your local device.
This setting affects only local playback quality.
Parameters
Parameter | Type | Description |
uid | String | The user ID—the unique identifier, typically assigned by your app server. |
volume | int | The playback volume. Valid range: [0, 100].
|
Return Description
0: The method executed successfully.
Non-zero: failed—for example, an invalid volume value.
muteLocalMic
Stops or resumes sending local audio data.
public abstract int muteLocalMic(boolean mute, AliRtcMuteLocalAudioMode mode);Muting sends silent frames. Capture and encoding continue to run.
When to call
You can call this before or after joining a channel.
Related callbacks
After the call succeeds, the remote user triggers <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ea457055e4izi" id="cce3d390a3xud">onUserAudioMuted</a> to notify the user whether they are muted.
Parameters
Parameter | Type | Description |
mute | boolean | Stops or resumes sending local audio data. Valid values:
|
mode | The mute mode. Default: microphone mute mode. |
Return description
0 indicates success. Other values indicate failure. Muting sends silent frames, but capture and encoding remain active.
muteRemoteAudioPlaying
Stops or resumes playing the audio track of a specific remote user.
public abstract int muteRemoteAudioPlaying(String uid, boolean mute);This operation is used only to stop or resume playback of audio from a specified remote user, but does not affect stream pulling or decoding of audio from remote users. To unsubscribe from the audio stream of a specific user, call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e09342eeb0z4k" id="66a2ef0919jjg">subscribeRemoteAudioStream</a>.
When to call
You can configure this before or after joining a channel.
Parameters
Parameter | Type | Description |
uid | String | The user ID. |
mute | boolean | Stops or resumes playing the remote user's audio. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
muteAllRemoteAudioPlaying
Stops or resumes playing all remote users' audio.
public abstract int muteAllRemoteAudioPlaying(boolean mute);This method stops or resumes playback of all remote users' audio.
This only stops playback. Pulling and decoding are unaffected.
When to call
You can configure this before or after joining a channel.
Parameters
Parameter | Type | Description |
mute | boolean | Stops or resumes playing all remote users' audio. Valid values:
|
Return Description
0 indicates success. Other values indicate failure.
startAudioCapture[1/2]
Starts audio capture.
public abstract int startAudioCapture();This method starts audio capture. You can also call it before joining to pre-start audio capture. If you do not set it, the SDK manages the audio capture device automatically. After calling stopAudioCapture to stop audio capture, call this method to restart.
When to call
You can call this before or after joining a channel.
Related methods
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b71a48f4b84n0" id="4565abdceeq8i">startAudioCapture[2/2]</a> interface lets you control whether the audio capture device remains in the enabling status after you leave the meeting using parameters.
Related callbacks
After calling this method to modify local audio capture status, use the onLocalAudioStateChanged callback to monitor changes.
Return description
0 indicates success. Other values indicate failure.
startAudioCapture[2/2]
Starts audio capture.
public abstract int startAudioCapture(boolean keepAlive);Stops microphone capture after muting.
This method starts audio capture. You can also call it before joining to pre-start audio capture. If you do not set it, the SDK manages the audio capture device automatically.
When to call
You can call this before or after joining a channel.
Related methods
Compared with startAudioCapture[1/2], this method lets you control whether the audio capture device stays on after leaving a channel using the keepAlive parameter.
Related callbacks
After calling this method to modify local audio capture status, use the onLocalAudioStateChanged callback to monitor changes.
Parameters
Parameter | Type | Description |
keepAlive | boolean | The audio capture device status after leaving a channel. Valid values:
|
Return Description
0 indicates success. Other values indicate failure.
stopAudioCapture
Stops audio capture.
public abstract int stopAudioCapture();The SDK enables audio capture by default. Without special configuration, actions like preview start and channel join automatically start audio capture. To stop audio capture, call this method.
Related callbacks
After calling this method to modify local audio capture status, use the onLocalAudioStateChanged callback to monitor changes.
Return description
0 indicates success. Other values indicate failure.
setDefaultAudioRoutetoSpeakerphone
Sets whether the default audio output is the speaker.
public abstract int setDefaultAudioRoutetoSpeakerphone(boolean defaultToSpeakerphone);This method sets the default audio routing device before joining a channel. You can choose earpiece or speaker output. The SDK defaults to speaker. To change this, call the method before joining.
The SDK defines internal audio routing priority and switches automatically based on connected peripherals. Priority order: Wired headset > Bluetooth headset > User setting > Default setting. So if no peripheral is connected and you have not used enableSpeakerphone, the default setting applies.
For more details about audio routing, see Audio Routing Settings.
Mobile devices usually support two audio routing options: earpiece and speaker:
Earpiece: Lower volume. Requires holding the phone near your ear for clear sound. Offers better privacy—ideal for calls.
Speaker: Higher volume. No need to hold the phone to your ear. Enables hands-free operation.
Related methods
This method modifies the default audio routing setting. Use enableSpeakerphone to set the current routing device.
When to call
You can call this before or after joining a channel.
Parameters
Parameter | Type | Description |
defaultToSpeakerphone | boolean | Whether to use the speaker by default.
|
Return Description
0: successful.
<0: failed.
enableSpeakerphone
Sets the audio output device to earpiece or speaker.
public abstract int enableSpeakerphone(boolean enable);This method sets the current audio playback device after joining a channel—choosing between earpiece and speaker. If you do not set this, playback uses the default audio routing device.
The SDK defines internal audio routing priority and switches automatically based on connected peripherals. Priority order: Wired headset > Bluetooth headset > User setting > Default setting. So if a peripheral is connected, this method has no effect. For more details, see Audio Routing Settings.
When to call
You can call this before or after joining a channel.
Related methods
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#d4dab00b21ebx" id="944fb5797e773">setDefaultAudioRoutetoSpeakerphone</a> modifies default audio routing settings. This interface sets the current routing device.
Parameters
Parameter | Type | Description |
enable | boolean | Set audio output to earpiece or speaker. Valid values:
|
Return Information
0 indicates success. Other values indicate failure.
isSpeakerOn
Queries whether the current audio output device is the earpiece or speaker.
public abstract boolean isSpeakerOn();Return description
true: speaker. false: earpiece.
enableAudioVolumeIndication
Enables user volume indication.
public abstract int enableAudioVolumeIndication(int interval, int smooth, int reportVad);This method lets the SDK periodically report volume information for the local user and the remote user with the highest instantaneous volume. To use it, implement the AliRtcAudioVolumeObserver class and register it using registerAudioVolumeObserver.
When to call
You can call this before or after joining a channel.
Related callbacks
After calling successfully, if users are publishing streams, the SDK triggers these callbacks at the configured interval:
Speaker volume is reported via AliRtcAudioVolumeObserver#onAudioVolume.
Voice activity detection triggers AliRtcAudioVolumeObserver#onActiveSpeaker to report the speaking user's UID.
Parameters
Parameter | Type | Description |
interval | int | Time interval
|
smooth | int | The smoothing factor. A higher value increases smoothing. A lower value reduces smoothing and improves real-time performance.
|
reportVad | int | The local voice detection toggle.
|
Return Description
0 indicates success. Other values indicate failure.
enableEarBack
Enables in-ear monitoring.
public abstract int enableEarBack(boolean enable);This method enables or disables in-ear monitoring. We recommend enabling it when using wired or Bluetooth headphones for best results.
When to call
You can call this before or after joining a channel.
Parameters
Parameter | Type | Description |
enable | boolean | Enables or disables in-ear monitoring. Valid values:
|
Return description
0 indicates success. Other values indicate failure.
setEarBackVolume
Sets the in-ear monitoring volume.
public abstract int setEarBackVolume(int volume) ;This method sets the in-ear monitoring volume. It takes effect only after enableEarBack is called.
When to call
You can call this before or after joining a channel.
Parameters
Parameter | Type | Description |
volume | int | The volume. Valid range: [0–100]. Default: 100.
|
Return value
0: successful.
<0: Method call failed.
startAudioPlayer
Starts the audio playback device.
public abstract int startAudioPlayer();This method pre-starts audio playback. If you do not set it, the SDK starts playback automatically after subscribing to an audio stream.
Return description
0: successful.
Non-zero: failed. Returns error code.
stopAudioPlayer
Stops the audio playback device.
public abstract int stopAudioPlayer();This method stops audio playback. It corresponds to startAudioPlayer.
Return description
0: successful.
Non-zero: failed. Returns error code.
setPlayoutVolume
Sets the local playback volume.
public abstract int setPlayoutVolume(int volume);Parameters
Parameter | Type | Description |
volume | int | The recording volume. Valid range: [0, 400].
|
Return description
0: successful.
Non-zero: failed.
setRecordingVolume
Sets the recording volume.
public abstract int setRecordingVolume(int volume);Parameters
Parameter | Type | Description |
volume | int | The recording volume. Valid range: [0, 400].
|
Return Description
0: successful.
Non-zero: failed.
playAudioFileTest
Plays an audio file.
public abstract int playAudioFileTest(String filePath) ;This method plays an audio file before joining a channel to test audio playback.
When to call
Call this only before joining a channel.
Limitations
Multiple calls overwrite each other. Calling this stops any currently playing file (if present).
Parameters
Parameter | Type | Description |
filePath | filePath | The file path. |
Return value
0: successful.
Non-zero: failed.
stopAudioFileTest
Stops audio file playback.
public abstract int stopAudioFileTest();This method corresponds to playAudioFileTest and stops audio file playback.
Limitations
Call this only before joining a channel.
Return description
0: successful.
Non-zero: failed.
startAudioCaptureTest
Starts audio capture device testing before a session begins.
public abstract int startAudioCaptureTest();This method starts audio capture testing to verify that the local audio capture device works properly before a session. After calling it, the SDK reports volume information via the AliRtcAudioVolumeObserver::onTestAudioVolume callback.
When to call
Call this before joining a channel. After testing completes, ensure you call stopAudioCaptureTest to stop testing and prevent device conflicts.
Return Description
0: successful.
Non-zero: failed. Returns error code.
stopAudioCaptureTest
Stops audio capture testing.
public abstract int stopAudioCaptureTest();This method stops audio capture testing. Call it after startAudioCaptureTest.
When to call
Call this before joining a channel.
Return value
0: successful.
Non-zero: failed. Returns error code.
setAudioEffectVoiceChangerMode
Sets the voice change effect mode.
public abstract int setAudioEffectVoiceChangerMode(AliRtcAudioEffectVoiceChangerMode mode);Parameters
Parameter | Type | Description |
mode | The voice change effect mode. Default: AliRtcSdk_AudioEffect_Voice_Changer_OFF (disabled). |
Return description
0 indicates success. Other values indicate failure.
setAudioEffectPitchValue
Sets the pitch adjustment value.
public abstract int setAudioEffectPitchValue(double value);Parameters
Parameter | Type | Description |
value | double | Pitch adjustment value. Range: [0.5, 2.0]. Default: 1.0 (no change). |
Return Description
0 indicates success. Other values indicate failure.
setAudioEffectReverbMode
Sets the reverberation effect mode.
public abstract int setAudioEffectReverbMode(AliRtcAudioEffectReverbMode mode);Parameters
Parameter | Type | Description |
mode | The reverberation effect mode. Default: AliRtcAudioEffectReverb_Off (disabled). |
Return description
0 indicates success. Other values indicate failure.
setAudioEffectReverbParamType
Sets the reverberation effect type and specific parameters.
public abstract int setAudioEffectReverbParamType(AliRtcAudioEffectReverbParamType type, float value);Parameters
Parameter | Type | Description |
type | The reverberation effect parameter. | |
value | float | The specific parameter value. |
Return Description
0 indicates success. Other values indicate failure.
setAudioEffectBeautifyMode
Sets a predefined voice beautification effect mode.
public abstract int setAudioEffectBeautifyMode(AliRtcAudioEffectBeautifyMode mode);This method configures built-in voice beautification modes in the SDK. It is ideal for scenarios requiring enhanced vocal quality—such as voice live streaming, karaoke, and voice social apps. Selecting different modes alters vocal perception—for example, boosting richness or clarity—to improve the listening experience for remote users.
When to call
You can call this before or after joining a channel.
Parameters
Parameter | Type | Description |
mode | The voice beautification effect mode. See the enumeration definition for details. |
Return description
0: successful.
Non-zero: failed.
setAudioEffectEqualizationParam
Sets audio equalizer (EQ) parameters to adjust gain for specific frequency bands.
public abstract int setAudioEffectEqualizationParam(AliRtcAudioEffectEqualizationBandFrequency bandIndex, float gain);This method applies graphic equalization to locally captured voice or audio signals. By adjusting gain (in dB) for one of ten fixed frequency bands, you can customize tonal characteristics. It is useful for speech clarity enhancement, vocal emphasis, and noise reduction assistance.
The equalizer supports full audio spectrum tuning—from 31 Hz to 16 kHz—with ten standard bands. Each band supports independent gain settings ranging from [-15, 15] dB. Default gain is 0 dB (no boost or attenuation).
Limitations
You cannot use the equalizer without first enabling a beautification mode. Call
setAudioEffectBeautifyModebefore calling this method.
Parameters
Parameter | Type | Description |
bandIndex | The frequency band index—corresponding to center frequencies (31 Hz to 16 kHz). | |
gain | float | The gain value, in dB. Range: [-15, 15]. |
Return Description
0: successful.
Non-zero: failed.
addExternalAudioStream
Adds an external audio stream.
public abstract int addExternalAudioStream(AliRtcExternalAudioStreamConfig config);This method adds an external audio stream. Follow these steps:
Invoke the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#42b363024fich" id="20c33a9acb0ui">addExternalAudioStream</a>API to add an external audio stream and obtain the external audio stream ID.Call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#930f22d3dcdco" id="d3deb62b2fl0f">pushExternalAudioStreamRawData</a>to send audio data to the created audio stream.When the call ends, you need to call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0333f86114078" id="16d826dedcli6">removeExternalAudioStream</a>to remove the external audio stream.
To publish custom-captured audio in a channel, see Custom Audio Capture.
Parameters
Parameter | Type | Description |
config | AliRtcExternalAudioStreamConfig | The external audio stream configuration. |
Return description
Values >0 indicate success and return the external audio stream ID. Other values indicate failure.
pushExternalAudioStreamRawData
Imports external audio stream data.
public abstract int pushExternalAudioStreamRawData(int streamId, AliRtcAudioFrame rawData);This method imports data into a specified audio stream. Follow these steps:
You can call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#42b363024fich" id="8822f2932e9ep">addExternalAudioStream</a>to add an external audio stream and retrieve the external audio stream ID.You can call the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#930f22d3dcdco" id="880fe8cd02j10">pushExternalAudioStreamRawData</a>operation to push audio data to the audio stream that you created.When you end the call, you must call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0333f86114078" id="106c7aefa27c0">removeExternalAudioStream</a>to remove the external audio stream.
For more information on publishing custom-captured audio in a channel, see Custom Audio Capture.
When to call
You can call this after you join a channel.
Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID. |
rawData | AliRtcAudioFrame | The audio data. |
Return description
A value of 0 indicates success. Any other value indicates failure.
setExternalAudioStreamPublishVolume
Sets the volume of an external audio stream for stream ingest.
public abstract int setExternalAudioStreamPublishVolume(int streamId, int publishVolume);Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID. |
publishVolume | int | The ingest volume. Valid range: [0, 100]. |
Return value
A return value of 0 indicates success. Other values indicate failure.
getExternalAudioStreamPublishVolume
Retrieves the volume of the external audio stream ingest.
public abstract int getExternalAudioStreamPublishVolume(int streamId);Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID. |
Return Description
The volume ranges from 0 to 100. A value less than 0 indicates failure.
setExternalAudioStreamPlayoutVolume
Sets the playback volume for external audio streams.
public abstract int setExternalAudioStreamPlayoutVolume(int streamId, int playoutVolume);Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID. |
playoutVolume | int | The playback volume. Valid range: [0, 100]. |
Return Description
0 indicates success. Other values indicate failure.
getExternalAudioStreamPlayoutVolume
Retrieves the playback volume of external audio streams.
public abstract int getExternalAudioStreamPlayoutVolume(int streamId);Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID. |
Return description
The playback volume, ranging from 0 to 100. A negative value indicates a failure.
removeExternalAudioStream
Removes an external audio stream.
public abstract int removeExternalAudioStream(int streamId);This method removes the external audio stream associated with the specified streamId. It complements the addExternalAudioStream method.
When to call
If you want to use custom audio input, call addExternalAudioStream to add an audio stream and obtain its ID. Then call pushExternalAudioStreamRawData to feed your audio data to the SDK. When you no longer need the custom audio input, call this method to remove the stream and release associated resources.
Parameters
Parameter | Type | Description |
streamId | int | The external audio stream ID—the return value of addExternalAudioStream on success. |
Return description
0: Success.
<0: Failure. Returns an error code.
getAudioFileInfo
Retrieves information about an audio file.
public abstract int getAudioFileInfo(String fileName);You can call this method asynchronously to retrieve the file duration. The method returns audio file information through the onAudioFileInfo callback.
Parameters
Parameter | Type | Description |
fileName | String | The audio file path. |
Back to Introduction
0: The operation succeeded.
A non-zero value: An error code is returned.
startAudioAccompany
Starts music accompaniment mixing.
public abstract int startAudioAccompany(String fileName, AliRtcAudioAccompanyConfig config) ;This method plays local or online accompaniment files. It is asynchronous. After calling this method, you can monitor the accompaniment playback status using AliRtcEngineNotify#onAudioAccompanyStateChanged.
When to call
You can call this method only after joining a channel.
Limitations
Unlike sound effects, only one accompaniment can play at a time. Repeated calls replace the previous accompaniment.
Parameters
Parameter | Type | Description |
fileName | String | The accompaniment file path. |
config | The accompaniment playback configuration—including local-only playback, mic replacement, loop count, playback position, and volume. |
Return Description
0: The operation was successful.
Non-zero: The operation failed. An error code is returned.
stopAudioAccompany
Stops music accompaniment mixing.
public abstract int stopAudioAccompany() ;This method corresponds to startAudioAccompany and stops accompaniment playback.
When to call
You can call this method before or after joining a channel.
Return Description
0: Success.
Non-zero: Failure. Returns an error code.
setAudioAccompanyVolume
You can use this method to set the volume of the audio accompaniment for both local playback and stream ingest.
public abstract int setAudioAccompanyVolume( int volume) ;This operation sets the audio accompaniment volume for both local playback and stream ingest. To set these volumes individually, use setAudioAccompanyPlayoutVolume for local playback and setAudioAccompanyPublishVolume for stream ingest.
Parameters
Parameter | Type | Description |
volume | int | The accompaniment volume. Valid range: [0, 100]. 0: muted. 100: original file volume. |
Return Description
0: The method call was successful.
A non-zero value: The method call failed. An error code is returned.
setAudioAccompanyPublishVolume
Sets the volume of the accompaniment stream ingest.
public abstract int setAudioAccompanyPublishVolume(int volume) ;Parameters
Parameter | Type | Description |
volume | int | The accompaniment volume. Valid range: [0, 100]. 0: muted. 100: original file volume. |
Return value
0: Success.
Non-zero: Failure. Returns an error code.
getAudioAccompanyPublishVolume
Queries the accompaniment stream ingest volume.
public abstract int getAudioAccompanyPublishVolume() ;Return Description
The stream ingest volume for accompaniment music.
[0–100]: successful.
Other values: error codes.
setAudioAccompanyPlayoutVolume
Sets the local playback volume for accompaniment.
public abstract int setAudioAccompanyPlayoutVolume(int volume) ;Parameters
Parameter | Type | Description |
volume | int | The accompaniment volume. Valid range: [0, 100]. 0: muted. 100: original file volume. |
Return description
0: successful.
Non-zero: failed. Returns error code.
getAudioAccompanyPlayoutVolume
Retrieves the local playback volume for accompaniment music.
public abstract int getAudioAccompanyPlayoutVolume() ;Return Description
The local playback volume for accompaniment music.
[0-100]: Success.
Other values indicate error codes.
pauseAudioAccompany
Pauses music accompaniment mixing.
public abstract int pauseAudioAccompany();Return description
0: successful.
Non-zero: failed. Returns error code.
resumeAudioAccompany
Resumes mixing of the music accompaniment.
public abstract int resumeAudioAccompany();Return Description
0: successful.
A non-zero value: failed. Returns an error code.
getAudioAccompanyDuration
Queries the accompaniment file duration in milliseconds.
public abstract int getAudioAccompanyDuration();This method queries the duration of the current accompaniment file.
Return value
>= 0: A value greater than or equal to 0 indicates the accompaniment file duration.
< 0: The operation failed. Returns an error code.
getAudioAccompanyCurrentPosition
Retrieves the accompaniment file's playback progress.
public abstract int getAudioAccompanyCurrentPosition();This method obtains the current playback progress of the accompaniment file, expressed in milliseconds.
Return Description
>=0: The accompaniment file's playback progress.
<0: The operation failed. An error code is returned.
setAudioAccompanyPosition
Sets the playback position of the accompaniment file.
public abstract int setAudioAccompanyPosition(int posMs);This method sets the playback progress of the accompaniment file, which is useful for features such as seek bars. After a successful call, playback starts from the specified position.
Parameters
Parameter | Type | Description |
posMs | int | The seek bar position—in milliseconds. |
Return Description
0: The call was successful.
A non-zero value: The call failed and an error code is returned.
preloadAudioEffect
Preloads a sound effect.
public abstract int preloadAudioEffect(int soundId, String filePath);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
filePath | String | The sound effect file path. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
unloadAudioEffect
Unloads a preloaded sound effect.
public abstract int unloadAudioEffect(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return description
A return value of 0 indicates success. A non-zero value indicates failure.
playAudioEffect
Plays a sound effect.
public abstract int playAudioEffect(int soundId, String filePath, int cycles, boolean publish);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
filePath | String | The sound effect file path. |
cycles | int | The number of playback loops. -1 means infinite looping. |
publish | boolean | Whether to ingest the sound effect audio stream to remote users. Valid values:
|
Return Description
Returns 0 on success. A non-zero value indicates failure.
stopAudioEffect
Stops the playback of a sound effect.
public abstract int stopAudioEffect(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return value
A return value of 0 indicates success. Any other value indicates failure.
stopAllAudioEffects
Stops the playback of all sound effects.
public abstract int stopAllAudioEffects();Return Description
0 is returned on success. Other values indicate failure.
setAudioEffectPublishVolume
Sets the volume for mixing sound effects into stream ingest.
public abstract int setAudioEffectPublishVolume(int soundId, int volume);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
volume | int | The volume of the mixed audio. Valid values: 0 to 100. Default value: 50. |
Return Description
0 indicates success. Other values indicate failure.
getAudioEffectPublishVolume
Retrieves the volume level used to mix sound effects into the stream ingest.
public abstract int getAudioEffectPublishVolume(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return value
A return value of 0 indicates success. Any other value indicates failure.
setAudioEffectPlayoutVolume
Sets the local playback volume for a sound effect.
public abstract int setAudioEffectPlayoutVolume(int soundId, int volume);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
volume | int | The mixed volume. Valid range: 0–100. Default: 50. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
getAudioEffectPlayoutVolume
Retrieves the local playback volume of a sound effect.
public abstract int getAudioEffectPlayoutVolume(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return description
Returns 0 on success. Other values indicate failure.
setAllAudioEffectsPublishVolume
Set the audio mixing volume for all sound effects during stream ingest.
public abstract int setAllAudioEffectsPublishVolume(int volume);Parameters
Parameter | Type | Description |
volume | int | The mixed volume. Valid range: 0–100. Default: 50. |
Return Description
0 indicates success. Other values indicate failure.
setAllAudioEffectsPlayoutVolume
Sets the local playback volume for all sound effects.
public abstract int setAllAudioEffectsPlayoutVolume(int volume);Parameters
Parameter | Type | Description |
volume | int | The mixed volume. Valid range: 0–100. Default: 50. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
startRecord
Starts recording a media file.
public abstract boolean startRecord(AliRtcRecordType recordType, AliRtcRecordFormat recordFormat, String filePath, AliRtcRecordAudioConfig audioConfig, AliRtcRecordVideoConfig videoConfig, long maxSize, long maxDuration);Parameters
Parameter | Type | Description |
recordType | The record type. | |
recordFormat | The format type (WAV, AAC, MP4). | |
filePath | String | The recording file name. |
audioConfig | The audio configuration. | |
videoConfig | The video configuration. | |
maxSize | long | The maximum file size. |
maxDuration | long | The maximum file duration. |
Return value
TRUE indicates success. Other values indicate failure.
When you record a video stream, call this API after stream ingest succeeds (
onVideoPublishStateChanged). This API records the locally encoded video stream and saves it to local storage.When recording audio streams, this method records a mixed audio file containing both local and remote audio.
stopRecord
Stops the media file recording.
public abstract void stopRecord();Parameters
None.
pauseAudioEffect
You can pause the sound effect.
public abstract int pauseAudioEffect(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
pauseAllAudioEffects
This method pauses all sound effects.
public abstract int pauseAllAudioEffects();Return Description
A return value of 0 indicates success. Any other value indicates failure.
resumeAudioEffect
You can restart the sound effect playback.
public abstract int resumeAudioEffect(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
Return Instructions
A return value of 0 indicates success. Any other value indicates failure.
resumeAllAudioEffects
Resumes playback of all sound effects.
public abstract int resumeAllAudioEffects();Return description
0 indicates success. Other values indicate failure.
createRenderSurfaceView
Creates a SurfaceView rendering view.
public abstract SophonSurfaceView createRenderSurfaceView(Context context);To display a video view, call this method instead of directly creating a SurfaceView. Follow these steps:
Assign the return value to AliRtcVideoCanvas#view.
Call setLocalViewConfig to set the local preview display view or setRemoteViewConfig to set the remote preview display view.
When to call
You can call this before or after joining a channel.
Limitations
You can call this method in the main thread.
Parameters
Parameter | Type | Description |
context | Context | The context of the Android activity. |
setLocalViewConfig
You can set the rendering window and drawing parameters for local preview.
public abstract int setLocalViewConfig(AliRtcVideoCanvas viewConfig, AliRtcVideoTrack track);This method sets the local preview view by binding the display window (view) for the local video stream and configuring the rendering mode, mirroring mode, and rotation angle. This setting affects only the local user’s preview and does not affect the published video stream. To set the remote user interface view, you can call setRemoteViewConfig.
If the view parameter in AliRtcVideoCanvas is empty, rendering stops.
To reset the renderMode parameter of AliRtcVideoCanvas during playback, change only the renderMode parameter without modifying any other parameters.
To reset the mirrorMode parameter of AliRtcVideoCanvas during playback, change only the mirrorMode parameter without modifying any other parameters.
We recommend that you explicitly call startPreview() to start the local preview.
When to call
You can call this method before or after joining a channel.
Parameters
Parameter | Type | Description |
viewConfig | The rendering parameters, including the rendering window and method. | |
track | The video track type. |
Return Description
A value of 0 indicates that the method call succeeded. Any other value indicates that the method call failed.
setRemoteViewConfig
Configures the rendering window and drawing parameters for a remote user's video stream.
public abstract int setRemoteViewConfig(AliVideoCanvas canvas, String uid,AliRtcVideoTrack track);This method binds a display view to a specified remote user's video stream and configures the local rendering mode, mirroring mode, and rotation angle for that user's video. This setting affects only the video displayed to the local user. To configure the local preview view, call setLocalViewConfig.
If the view parameter in AliRtcVideoCanvas is empty, rendering stops.
To reset the renderMode parameter of AliRtcVideoCanvas during playback, modify only renderMode while keeping all other parameters unchanged.
To reset the mirrorMode parameter of AliRtcVideoCanvas during playback, modify only mirrorMode while keeping all other parameters unchanged.
When to call
You can call this method after you receive the onRemoteTrackAvailableNotify callback—that is, when the remote user's video stream becomes available.
Parameters
Parameter | Type | Description |
canvas | The rendering parameters, including the rendering window and method. | |
uid | String | The user ID. |
track | The video track type to set. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
setCameraCapturerConfiguration
You can use this method to configure camera capture preferences, such as camera direction and frame rate.
public abstract int setCameraCapturerConfiguration(AliEngineCameraCapturerConfiguration cameraCapturerConfiguration);This method configures camera capture preferences, such as camera direction and frame rate.
When to call
Call this method before opening the camera—for example, before calling:
startPreview (Start preview)
joinChannel (to join a channel)
Parameters
Parameter | Type | Description |
cameraCapturerConfiguration | Camera capture preferences, including camera direction and frame rate. Default values:
-1 indicates using the SDK's internal default settings. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
enableLocalVideo
Disables or enables local video capture.
public abstract int enableLocalVideo(boolean enable);This method controls local video capture. When disabled, the local preview and stream ingest will not have video data, but receiving remote video is not affected. If you use this method to disable local camera capture, the video freezes on the last captured frame for both the local preview and for remote viewers.
Local video capture is enabled by default.
When to call
You can call this method before or after joining a channel.
Related callbacks
After a successful call to this method, the onUserVideoEnabled callback is triggered for remote users.
Parameters
Parameter | Type | Description |
enable | boolean | Disables or re-enables local video capture. Valid values:
|
Return value
0 indicates success. Any other value indicates failure.
muteLocalCamera
You can stop or resume sending local video data.
public abstract int muteLocalCamera(boolean mute, AliRtcVideoTrack track);When ingesting a stream, you can call this method to send black video frames without affecting the local preview or interrupting the capture, encoding, and sending modules.
This method controls whether black frames are sent on a specified video track. Collection and data transmission processes are not affected. To disable collection, use the enableLocalVideo method. To stop sending video data, use the publishLocalVideoStream method or call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7558afe6accq4" id="ee17216e55r3t">enableLocalVideo</a> stop collection.
Parameters
Parameter | Type | Description |
mute | boolean | Stops or resumes sending local video data. Valid values:
|
track | The video track type for which to change the publishing status. |
Return description
A value of 0 indicates success.
isCameraOn
Determines whether the camera is enabled.
public abstract boolean isCameraOn();Return value
true: The camera is enabled. false: The camera is disabled.
setVideoEncoderConfiguration
Sets the video encoding properties.
public abstract void setVideoEncoderConfiguration(AliRtcVideoEncoderConfiguration config);This method sets the encoding parameters for a video stream, such as resolution, frame rate, bitrate, and video orientation. We recommend that you call this method in all video scenarios.
Each parameter has a valid value range. If you set a parameter to a value outside the valid range, the SDK automatically adjusts it. As a result, the actual configuration may differ from your settings.
When to call
You can call this method before or after you join a channel. If you only need to set the video encoding properties for the camera stream once per session, we recommend that you call this method before you join the channel.
Limitations
Both the mirrorMode parameter in this method and the setVideoMirrorMode method set video stream mirroring. We recommend that you use only one of these methods. Using both can cause the mirroring effects to overlap, which may result in failed or incorrect mirroring.
Parameters
Parameter | Type | Description |
config | Predefined encoding properties. Default values:
-1 indicates using the SDK's internal default settings. |
setVideoDecoderConfiguration
Sets the video decoding properties.
public abstract void setVideoDecoderConfiguration(AliRtcVideoDecoderConfiguration config);This method configures video parameters for decoding a video stream.
When to call
You can call this method before joining a channel.
Parameters
Name | Type | Description |
config | AliRtcVideoDecoderConfiguration | Predefined decoding properties. Default values:
-1 indicates using the SDK's internal default settings. |
switchCamera
Switches between the front and rear cameras. By default, the front camera is used.
public abstract int switchCamera();You can call this method to dynamically switch cameras during runtime without restarting the video stream or reconfiguring the video source.
When to call
Call this method only after the camera is successfully enabled.
Limitations
This method is available only on Android and iOS platforms.
Return Description
A return value of 0 indicates success. Any other value indicates failure.
getCurrentCameraDirection
Retrieves the current camera direction.
public abstract AliRTCCameraDirection getCurrentCameraDirection();Return value
CAMERA_REAR (0) indicates the rear camera.
CAMERA_FRONT (1) indicates the front camera.
CAMERA_INVALID (-1) indicates an invalid state.
You can call this method only after the camera is turned on. Otherwise, it returns CAMERA_INVALID (-1).
startPreview
Start the local preview.
public abstract int startPreview();This method starts a local video preview and automatically turns on the camera. To stop the local preview, you can call stopPreview.
In addition to stopping the local preview, the leaveChannel call also turns off the camera if no camera stream is being published.
When to Call
You must call `setLocalViewConfig` to set the view for the local preview before you start a call. Otherwise, the preview will fail, but stream ingest will be unaffected.
You can call this method to start the preview before you call `joinChannel`. The camera turns on automatically.
Return description
A return value of 0 indicates success. Any other value indicates failure.
stopPreview
Stops the local video preview and turns off the camera.
public abstract int stopPreview();After you stop the preview, the local display remains on the last frame. Stream ingest is unaffected.
leaveChannel automatically stops the local preview. If no camera stream is published, the camera automatically turns off.
When to call
You can call this method to stop the preview after it has started.
Return value
A return value of 0 indicates success. Any other value indicates failure.
setCameraZoom
Sets the camera’s zoom factor.
public abstract int setCameraZoom(float zoom);This method sets the camera’s zoom factor.
Limitations
This method is supported only on iOS and Android.
When to call
You can set the zoom factor only after enabling the camera. The zoom factor resets each time the camera restarts.
Parameters
Parameter | Type | Description |
zoom | float | The camera zoom factor. Range: 1 to the maximum supported zoom value. Query the maximum supported zoom factor using getCameraMaxZoomFactor. |
Returns
0: The call succeeded.
A non-zero value: The call failed.
getCameraMaxZoomFactor
Queries the maximum supported camera zoom (digital zoom) factor.
public abstract float GetCameraMaxZoomFactor();Return Instructions
The maximum zoom factor supported by the device camera.
getCurrentZoom
Retrieves the current camera zoom factor.
public abstract float GetCurrentZoom();Return description
The current camera zoom factor.
SetExposure
Set the exposure level of the camera.
public abstract int SetExposure(float exposure);An excessively dark or bright shooting environment can affect the quality of the captured video. To achieve better video effects, you can use this method to adjust the camera's exposure level. You can query the supported exposure range using getMinExposure and getMaxExposure.
Parameters
Parameter | Type | Description |
exposure | float | The camera exposure level. Default: 0, indicating the camera's default exposure. Higher values increase exposure. Decrease exposure if the video is overexposed; increase it if underexposed areas lose detail. If the provided exposure is outside the supported range, the SDK automatically adjusts it. |
Return value
0: Success.
Non-zero: Failure.
getCurrentExposure
Queries the exposure level of the currently active camera.
public abstract float GetCurrentExposure();Queries the exposure level of the currently active (camera).
Return description
The current camera exposure level.
GetMinExposure
Retrieves the minimum supported camera exposure level.
public abstract float GetMinExposure();Return Description
The minimum camera exposure level.
GetMaxExposure
Returns the maximum supported camera exposure level.
public abstract float GetMaxExposure();Return Description
The maximum camera exposure level.
setCameraFlash
Turns the camera flash on or off.
public abstract int setCameraFlash(boolean flash);You can turn the flash on or off.
Typically, only rear cameras have flash functionality.
Limitations
This method is available only on iOS and Android.
Parameters
Parameter | Type | Description |
flash | boolean | Whether to turn on the flash.
|
Return description
0: successful.
Non-zero: failed.
isCameraFocusPointSupported
Determines whether the current device supports manual focus.
public abstract boolean isCameraFocusPointSupported();Determines whether the current camera can set a focus point to support manual focus.
Limitations
This method is supported only on iOS and Android.
Return Description
true: The device supports manual focus.
false: The device does not support manual focus.
isCameraExposurePointSupported
Determines whether the device supports setting a camera exposure point.
public abstract boolean isCameraExposurePointSupported();This method determines whether the current device supports setting a camera exposure point.
Limitations
This method is supported only on iOS and Android.
Return description
true: The device supports setting a camera exposure point.
false: The device does not support setting a camera exposure point.
setCameraFocusPoint
You can set the camera's manual focus point.
public abstract int setCameraFocusPoint(float x, float y);Sets the focus point for the current camera. After you call this method, the camera performs a single exposure adjustment to the specified point and maintains that focus value. Before you call this method, check whether the device supports manual focus using isCameraFocusPointSupported.
Limitations
This method is only available on iOS and Android.
Parameters
Parameter | Type | Description |
x | float | The X-axis coordinate value. |
y | float | The Y-axis coordinate value. |
Return description
0: Success.
Non-zero: Failure.
setCameraExposurePoint
Sets the camera exposure point.
public abstract int setCameraExposurePoint(float x, float y);After you call this method, the camera performs a single exposure adjustment to the specified point and maintains that exposure value. Before you call this method, we recommend that you use isCameraExposurePointSupported to check if the device supports setting the exposure point.
Limitations
This method is available only on iOS and Android.
Parameters
Parameter | Type | Description |
x | float | The X-axis coordinate value. |
y | float | The Y-axis coordinate value. |
Return Description
0: The call was successful.
Non-zero: The call failed.
isCameraAutoFocusFaceModeSupported
Checks whether the camera supports automatic face focus.
public abstract boolean isCameraAutoFocusFaceModeSupported();Determines whether the camera supports automatic face focus.
When to call
You can call this method only after the camera is enabled. If this method is called before the camera is enabled, it returns false by default. The method returns true if the camera is enabled and supports automatic face focus.
Limitations
This method is available only on iOS and Android.
Return Description
true: The camera supports automatic face focus.
false: The camera does not support automatic face focus.
setCameraAutoFocusFaceModeEnabled
Set the face focus for the camera.
public abstract boolean setCameraAutoFocusFaceModeEnabled(boolean enable);This method enables or disables real-time face detection for camera focus. Before you call this method, verify device support using isCameraAutoFocusFaceModeSupported.
Limitations
This method is available only on iOS and Android.
Parameters
Parameter | Type | Description |
enable | boolean | Enables or disables camera face focus.
|
Return Description
true: The call succeeds.
false: The call failed.
setVideoMirrorMode
You can configure the preview and stream ingest video mirroring capability.
public abstract int setVideoMirrorMode(AliRtcVideoPipelineMirrorMode mirrorMode);Enables or disables mirroring for the local video preview and published video streams.
This method takes precedence over setLocalViewConfig and setVideoEncoderConfiguration. We recommend using this method to set the video mirroring mode.
When to call
You can dynamically set this before or after joining a channel. The SDK records the state and applies video operations when preview and encoding (stream ingest) are active.
Limitations
This method overlaps with the mirrorMode settings in setLocalViewConfig and setVideoEncoderConfiguration. You can use only one of these methods.
Parameter description
Parameter | Type | Description |
mirrorMode | The mirroring mode. |
Return Description
0 indicates success.
<0: setting failed.
ERR_INNER (–1): An internal SDK state error occurred. Verify that the SDK instance was created successfully.
setCapturePipelineScaleMode
Sets the timing for video capture scaling.
public abstract void setCapturePipelineScaleMode(AliRtcCapturePipelineScaleMode mode);Determines whether video capture scaling occurs during capture or during encoding. For example, when the capture resolution differs from the encoding resolution, you can set the scaling timing to ensure that preview data matches published data.
When to call
You can set this before opening the camera—for example, before calling startPreview or joinChannel.
Parameters
Parameter | Type | Description |
mode | AliRtcCapturePipelineScaleMode | The mode controlling the timing of capture scaling. Default: immediate scaling during capture. |
Return description
None.
setExternalVideoSource
You can enable an external video input source.
public abstract void setExternalVideoSource(boolean enable,boolean useTexture,
AliRtcVideoTrack streamType,AliRtcRenderMode renderMode);Parameters
Parameter | Type | Description |
enable | boolean | Enables the external video input source. Valid values:
|
useTexture | boolean | Whether to use texture mode. Valid values:
|
type | The video stream type. | |
renderMode | The rendering mode. |
pushExternalVideoFrame
Enter the video data.
public abstract int pushExternalVideoFrame(AliRtcRawDataFrame aliRawDataFrame,AliRtcVideoTrack streameType);Parameters
Parameter | Type | Description |
aliRawDataFrame | The frame data. | |
streameType | The type of video stream. |
Return value
Returns 0 if the operation is successful. Otherwise, an error code is returned.
startPublishLiveStream
Starts relayed live streaming.
public abstract int startPublishLiveStream(String streamUrl,AliRtcLiveTranscodingParam transcodingParam);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL. |
transcodingParam | The stream ingest parameters. |
Return Instructions
Returns 0 on success, or a non-zero value on failure.
updatePublishLiveStream
Updates the parameters for a relayed live stream.
public abstract int updatePublishLiveStream(String streamUrl,AliRtcLiveTranscodingParam transcodingParam);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL. |
transcodingParam | The stream ingest parameters. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
stopPublishLiveStream
Stops the relayed live stream.
public abstract int stopPublishLiveStream(String streamUrl);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
getPublishLiveStreamState
You can use this method to query the status of relayed live streaming.
public abstract AliRtcEngine.AliRtcLiveTranscodingState getPublishLiveStreamState(String streamUrl);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL for relayed live streaming. |
Return Description
This method returns the status of relayed live streaming.
startNetworkQualityProbeTest
Starts network quality testing.
public abstract int startNetworkQualityProbeTest(AlirtcNetworkQualityProbeConfig config);Parameters
Parameter | Type | Description |
config | AlirtcNetworkQualityProbeConfig | Parameters for configuring the probe. |
Return description
0 indicates success. Other values indicate failure.
stopNetworkQualityProbeTest
Stops the network quality test.
public abstract int stopNetworkQualityProbeTest();Return description
A return value of 0 indicates success. Any other value indicates failure.
sendMediaExtensionMsg
Send media extension information.
public abstract int sendMediaExtensionMsg(byte[]message, int repeatCount, int delay, boolean isKeyFrame);The SDK enables you to send and receive media extension messages. This method sends media extension messages using the SEI extension protocol. Receivers can retrieve messages by listening to onMediaExtensionMsgReceived.
Common use cases include the following:
You can use media extension messages to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business logic.
You can use media extension messages to transmit descriptive information. Currently, up to 4 KB of data can be transmitted, which is suitable for small amounts of data. We recommend using JSON or plain strings.
When to call
You can call this after starting stream ingest.
Limitations
Media extension messages share the audio and video data channel. Therefore, you must control the sending frequency and data length of custom messages. The limitations are as follows:
You can send a maximum of fps messages per second, as configured in the profile. This is because SEI information is transmitted within H.264/H.265 streams, and extension information can only be attached when video frames are encoded.
To avoid impacting media data transmission quality, the custom message body length is limited to 4 KB, making it suitable for transmitting small amounts of information.
The repeatCount parameter in sendMediaExtensionMsg specifies message redundancy. If its value is greater than 1, the message is sent multiple times.
This prevents message loss due to packet loss. Other participants in the room will receive duplicate messages, which require deduplication.
Subscribers in relayed live streaming also receive custom messages.
Only one MediaExtensionMsg can be transmitted at a time. Multiple calls to sendMediaExtensionMsg will overwrite previous data.
Related callbacks
When a publisher sends media extension messages, subscribers receive them in the onMediaExtensionMsgReceived callback.
Parameters
Parameter | Type | Description |
message | byte[] | The media extension message. Max length: 4 KB. |
repeatCount | int | The repeat count, representing message redundancy to prevent loss due to packet loss. -1 means infinite transmission. |
delay | int | The delay, in milliseconds. The minimum delay after calling the API to send the extension message. |
isKeyFrame | boolean | Whether to use extension information only for keyframes. true means extension information is attached only to keyframes. |
Return description
0: Success.
<0: The call failed, returning an error code.
ERR_INNER(-1): SDK internal error. Possible causes: The SDK was not initialized, or it was called after it was destroyed.
sendMediaExtensionMsgEx
Send media extension information.
public abstract int sendMediaExtensionMsgEx(byte[]message, int repeatCount, int delay, boolean isKeyFrame, int payloadType);The SDK provides functions for sending and receiving media extension messages. This method sends media extension messages using the SEI extension protocol. Receivers can obtain messages by listening to onMediaExtensionMsgReceived. If the payloadType is 5, it is equivalent to using the sendMediaExtensionMsg method.
Common use cases include the following:
You can use media extension messages to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business logic.
You can use media extension messages to transmit descriptive information. The data size is limited to 4 KB, which is suitable for small payloads. We recommend using JSON or plain strings.
When to call
You can call this after starting stream ingest.
Limitations
Because media extension messages use the audio/video data channel, you must control the sending frequency and data length of custom messages. The limitations are as follows:
You can send a maximum of fps messages per second, as specified in the profile, because SEI information is transmitted within H.264 or H.265 streams and extension information can be attached only when video frames are encoded.
To avoid affecting media data transmission quality, the custom message body length is limited to 4 KB, which is suitable for transmitting small amounts of information.
The repeatCount parameter in sendMediaExtensionMsg specifies message redundancy. If this parameter is greater than 1, the message is sent multiple times.
This prevents message loss due to packet loss. Other participants in the room receive duplicate messages and must perform deduplication.
Subscribers in relayed live streaming also receive custom messages.
Only one MediaExtensionMsg is transmitted at a time. Multiple calls to sendMediaExtensionMsg overwrite previous data.
Return value
Parameter | Type | Description |
message | byte[] | The media extension message. Max length: 4 KB. |
repeatCount | int | The repeat count, representing message redundancy to prevent loss due to packet loss. -1 means infinite transmission. |
delay | int | The delay, in milliseconds. The minimum delay after calling the API to send the extension message. |
isKeyFrame | boolean | Whether to use extension information only for keyframes. true means extension information is attached only to keyframes. |
payloadType | int | Payload type range: [5, 100–254]. payloadType=5 is equivalent to using the sendMediaExtensionMsg method. |
Return description
0: The operation was successful.
<0: The call failed, returning an error code.
ERR_INNER(-1): An internal SDK error. This error occurs when the SDK is called before initialization or after destruction.
onConnectionStatusChange
This callback is invoked when the network connection status changes.
public void onConnectionStatusChange(AliRtcEngine.AliRtcConnectionStatus status,
AliRtcEngine.AliRtcConnectionStatusChangeReason reason);Parameters
Parameter | Type | Description |
status | The current network connection status. | |
reason | The reason for the network connection status change. |
OnLocalDeviceException
An abnormal callback is received from an on-premises device. You need to handle this callback.
public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg)Parameter description
Parameter | Type | Description |
deviceType | AliRtcEngineLocalDeviceType | The device type. |
exceptionType | AliRtcEngineLocalDeviceExceptionType | The device exception type. |
msg | String | The information carried in the exception. |
onAuthInfoWillExpire
This callback is triggered when user authentication is about to expire. Authentication expires 30 seconds after you receive this callback. Monitor this callback closely.
public void onAuthInfoWillExpire();This callback indicates that user authentication information is about to expire. Authentication expires 30 seconds after you receive this callback. You can obtain a new token and update the authentication information using one of the following methods:
Call the
<a baseurl="t2309760_v6_4_1.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#975b9af9ecq1a" id="8099ac5a509hn">refreshAuthInfo</a>API to update the authentication information.Call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="fe88be037dy4g">leaveChannel</a>to leave the current channel, and then calljoinChannelto rejoin the channel.
Trigger timing
The SDK triggers this callback 30 seconds before user authentication information expires. You must update the authentication information promptly after receiving this callback.
onAuthInfoExpired
When a user calls an API that requires authentication, the server-side returns an "information expired" message.
public void onAuthInfoExpired();To continue the session, generate a new token on the server and update the authentication information using the following method:
Call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="c3b0cf2f19dgm">leaveChannel</a>to leave the current channel, and then calljoinChannelto rejoin the channel.
Trigger timing
This callback is triggered when user authentication information expires.
onJoinChannelResult
This callback returns the result of joining a channel.
public void onJoinChannelResult(int result, String channel, String userId, int elapsed);Parameters
Parameter | Type | Description |
result | int | The result of joining the channel. 0 indicates success. Other values indicate failure and return an error code. For details, see Error codes. Common error codes include the following:
|
channel | String | The channel ID. |
userId | String | The user ID. |
elapsed | int | The time elapsed to join the channel, in milliseconds. |
onLeaveChannelResult
This callback is invoked to return the result of leaving a channel.
public void onLeaveChannelResult(int result, AliRtcEngine.AliRtcStats stats);Trigger conditions
This callback is triggered when the application successfully invokes <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="7f3d2133c81tx">leaveChannel</a> to leave the channel, providing the result and the performance statistics for the current channel session.
If you call destroy to destroy the engine immediately after <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="fdccda828dzqt">leaveChannel</a>, this callback is not triggered.
Parameters
Parameter | Type | Description |
result | int | The result of leaving the channel. 0 indicates success. Other values indicate failure and return an error code. |
stats | A summary of session statistics within the channel. |
onRemoteUserOffLineNotify
Callback for remote user offline events.
public void onRemoteUserOffLineNotify(String uid, AliRtcUserOfflineReason reason);This callback is triggered when a remote user goes offline, indicating that the user has left the channel.
Trigger Conditions
This callback is triggered when a remote user actively leaves the channel.
The callback is triggered when a remote streamer switches to the viewer role by calling
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="4c0adbe948tif">setClientRole</a>with the role set to AliRTCSdkLive.If the remote streamer sends no data for an extended period and is considered offline, the callback is triggered.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
reason | The reason for the user going offline. |
onRemoteUserOnLineNotify
Triggered when a remote user goes online.
public void onRemoteUserOnLineNotify(String uid, int elapsed);This interface notifies the local client when a remote user joins the channel.
Trigger Conditions
The remote user joined the channel successfully.
When the current user joins a channel, they receive join callbacks for users who are already in the channel. You can use these callbacks to display the users who joined previously.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
elapsed | int | The time elapsed for the user to join the channel, in milliseconds. |
onRemoteTrackAvailableNotify
A callback is triggered when a remote user’s audio or video stream changes.
public void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack,
AliRtcVideoTrack videoTrack);This callback is triggered when a remote user’s stream ingest status changes. It enables developers to determine in real time whether a remote user is publishing audio or video streams and to display or hide the remote user’s audio or video information accordingly.
This callback returns the remote user’s stream ingest status. To identify which stream went offline, record the state changes before and after the callback.
Trigger Condition
This callback is triggered in the following scenarios:
When a remote user starts publishing audio and video.
When a remote user stops publishing audio and video.
In interactive mode, when a remote user calls setClientRole to switch from viewer to streamer and also enables stream ingest, this callback is triggered.
For example, if a remote user is not publishing video, this callback does not trigger:
When the remote user starts publishing a camera stream (publishing status changes from no video stream to camera stream only), the local callback returns
AliRtcVideoTrackCamera, indicating that the remote user’s camera stream is available.When a remote user who is publishing a camera stream also starts to publish a screen-sharing stream, the local callback returns
AliRtcVideoTrackBoth. This indicates that both the camera and screen-sharing streams are available.When the remote user stops publishing the camera stream and publishes only the screen-sharing stream (publishing status changes from camera stream and screen-sharing stream to screen-sharing stream only), the local callback returns
AliRtcVideoTrackScreen, indicating that only the screen-sharing stream is available.When the remote user stops publishing the screen-sharing stream (publishing status changes from screen-sharing stream only to no video stream), the local callback returns
AliRtcVideoTrackNo, indicating that no video stream is available.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
audioTrack | The audio stream of the remote user after the change. | |
videoTrack | The video stream of the remote user after the change. |
onBye
This callback is invoked when you are disconnected from the server or the channel is closed.
public void onBye(int code);This callback is triggered when a user is disconnected or a session ends. Developers can then use the code parameter to determine the cause of the disconnection and handle it accordingly.
Trigger conditions
The server terminates the current user’s session.
The server actively removes the channel, ending the session.
A passive disconnection occurs, requiring the client to attempt session recovery or reconnection.
Parameters
Parameter | Type | Description |
code | int | The onBye type. For more information, see AliRtcOnByeType. |
onAudioPublishStateChanged
This callback is invoked when an audio track's stream ingest status changes.
public void onAudioPublishStateChanged(AliRtcEngine.AliRtcPublishState oldState ,
AliRtcEngine.AliRtcPublishState newState,
int elapseSinceLastState, String channel);This callback monitors changes to the local user's audio stream ingest status.
Trigger conditions
This callback is triggered when a user's audio stream ingest status changes, such as:
Stopping stream ingest.
Invoking
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="e6c8edfc45xbw">setClientRole</a>to switch to the viewer role.
Parameters
Parameter | Type | Description |
oldState | The previous stream ingest status. | |
newState | The current stream ingest status. | |
elapseSinceLastState | int | The time elapsed since the last state change, in milliseconds. |
channel | String | The current channel ID. |
onAudioSubscribeStateChanged
This callback is invoked when the audio track subscription status changes.
public void onAudioSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback notifies the local user about changes in a remote user's audio stream subscription status. It provides the subscription status change for a remote user's camera stream and the time elapsed since the previous state.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
oldState | The previous subscription status. | |
newState | The current subscription status. | |
elapseSinceLastState | int | The time elapsed since the last state change, in milliseconds. |
channel | String | The current channel ID. |
onUserAudioMuted
This callback is invoked when a remote user stops sending audio data.
public void onUserAudioMuted(String uid ,boolean isMute);Parameters
Parameter | Type | Description |
uid | String | The user who executed muteAudio. |
isMute | boolean | Whether muted. Valid values:
|
onUserAudioInterruptedBegin
This callback is invoked when a user's audio is interrupted.
public void onUserAudioInterruptedBegin(String uid);Parameters
Parameter | Type | Description |
uid | String | The user whose audio was interrupted. |
onUserAudioInterruptedEnded
This callback is invoked when an audio interruption ends for a user.
public void onUserAudioInterruptedEnded(String uid);Parameters
Parameter | Type | Description |
uid | String | The user whose audio was interrupted. |
onVideoPublishStateChanged
The callback that is invoked when the publishing state of a video stream changes.
public void onVideoPublishStateChanged(AliRtcEngine.AliRtcPublishState oldState ,
AliRtcEngine.AliRtcPublishState newState,
int elapseSinceLastState, String channel);This callback monitors changes in the local user's video stream ingest status.
Parameters
Parameter | Type | Description |
oldState | The previous stream ingest status. | |
newState | The current stream ingest status. | |
elapseSinceLastState | int | The time interval for a state change in milliseconds. |
channel | String | The current channel ID. |
onVideoSubscribeStateChanged
A callback that is invoked when the subscription status for a camera stream changes.
public void onVideoSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback notifies the local user when a remote user’s camera stream subscription status changes. It reports the new subscription status and the time elapsed since the previous status.
Related callbacks
Video streams include camera streams and screen-sharing streams. This method reports subscription status changes for camera streams. The corresponding callback for screen-sharing streams is onScreenShareSubscribeStateChanged.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
oldState | The previous subscription status. | |
newState | The current subscription status. | |
elapseSinceLastState | int | The time elapsed since the last state change. |
channel | String | The current channel ID. |
onUserVideoMuted
This callback is invoked when a remote user sends black video frames.
public void onUserVideoMuted(String uid, boolean isMute);Parameters
Parameter | Type | Description |
uid | String | The user who executed enableLocalVideo. |
isMute | boolean | Whether black frames are sent. Valid values:
|
onUserVideoEnabled
This callback is invoked when a remote user disables camera capture.
public void onUserVideoEnabled(String uid, boolean isMute);Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
isMute | boolean | Whether camera stream capture is enabled. Valid values:
|
onUserWillResignActive
The remote user's application moves to the background.
public void onUserWillResignActive(String uid);Parameters
Parameter | Type | Description |
uid | String | The user ID. |
onUserWillBecomeActive
This callback is invoked when a remote user switches the app back to the foreground.
public void onUserWillBecomeActive(String uid);Parameters
Parameter | Type | Description |
uid | String | The user ID. |
onAliRtcStats
This callback is invoked to report current session statistics and is triggered by the SDK every two seconds.
public void onAliRtcStats(AliRtcEngine.AliRtcStats stats);Parameters
Parameter | Type | Description |
stats | The session statistics. |
onAudioEffectFinished
This callback is invoked when the playback of a local sound effect finishes.
void OnAudioEffectFinished(int soundId);Parameters
Parameter | Type | Description |
soundId | int | The ID assigned by the user to the sound effect. |
onAudioFileInfo
The callback that is invoked when audio file information becomes available.
public void onAudioFileInfo(AliRtcEngine.AliRtcAudioFileInfo info, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);You can call getAudioFileInfo to retrieve audio file information. This callback is triggered to return the file duration or an error message.
Parameters
Parameter | Type | Description |
info | AliRtcEngine.AliRtcAudioFileInfo | Audio file information, including file path and duration. |
errorCode | AliRtcEngine.AliRtcAudioAccompanyErrorCode | The audio accompaniment error code, primarily for file open or decode failures. |
onMediaExtensionMsgReceived
The callback that is invoked when media extension messages are received.
public void onMediaExtensionMsgReceived(String uid, int payloadType, byte[]message);When one endpoint sends messages using sendMediaExtensionMsg, other endpoints receive the data through this callback.
Parameters
Parameter | Type | Description |
uid | String | The user ID of the sender. |
payloadType | int | The payload type. sendMediaExtensionMsg returns 5. sendMediaExtensionMsgEx returns the specific type. |
message | byte[] | The media extension message. |
onFirstRemoteVideoFrameDrawn
This callback is invoked when the first remote video frame is rendered.
public void onFirstRemoteVideoFrameDrawn(String uid,AliRtcVideoTrack videoTrack, int width, int height, int elapsed);This callback is triggered when the first remote video frame is successfully received and rendered. It helps developers monitor remote video link establishment time, evaluate network and device performance, and optimize the user experience.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
videoTrack | The received video stream type. | |
width | int | The width of the pulled video. |
height | int | The height of the pulled video. |
elapsed | int | The total delay, in milliseconds, from the local user joining the channel until the first frame of the pulled video is displayed. |
onFirstLocalVideoFrameDrawn
The callback that is invoked when the first video frame is rendered during preview.
public void onFirstLocalVideoFrameDrawn(int width, int height, int elapsed);This callback is triggered when the first local video frame is rendered after the local user enables the camera. It helps developers monitor the speed at which the local video preview is established, evaluate device performance, and optimize the user experience—for example, by displaying "Camera ready" or adjusting the preview layout.
Parameters
Parameter | Type | Description |
width | int | The width of the local preview video. |
height | int | The height of the local preview video. |
elapsed | int | The total delay, in milliseconds, from the local user joining the channel until the first frame of the local preview is displayed. |
onFirstVideoFrameReceived
The callback that is invoked when the first remote video frame is received.
public void onFirstVideoFrameReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost);This callback notifies the local user when the first remote video frame is successfully received. It helps developers monitor video link establishment time, evaluate network quality, and optimize user experience—for example, by displaying "Video ready" or adjusting playback logic.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
videoTrack | The received video stream type. | |
timeCost | int | The time elapsed, in milliseconds, from joining the channel until the first video packet is sent. |
onFirstVideoPacketSent
This callback is invoked when the first video packet is sent.
public void onFirstVideoPacketSent(String uid, AliRtcVideoTrack videoTrack, int timeCost);This callback indicates when the local user successfully sends the first local video packet. It helps developers monitor the speed of video link establishment, evaluate local device performance, and optimize user experience, such as displaying "Video sent" or adjusting the capture policy.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
videoTrack | The received video stream type. | |
timeCost | int | The time elapsed, in milliseconds, from joining the channel until the first video packet is sent. |
onFirstAudioPacketSent
This callback is invoked when the first audio packet is sent.
public void onFirstAudioPacketSent(String uid, AliRtcAudioTrack track, int timeCost);This callback notifies you that the first local audio packet has been sent successfully. You can use this callback to monitor the audio link establishment speed, evaluate the performance of the local device and system, and optimize the user experience.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
track | The received audio stream type. | |
timeCost | int | The time elapsed, in milliseconds, from joining the channel until the first audio packet is sent. |
onFirstVideoPacketReceived
This callback is invoked when the local user receives the first video packet from a remote user.
public void onFirstVideoPacketReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost)This interface is a callback, triggered when the local user receives the first video packet from a remote user. You can use this callback to monitor the video link establishment speed or update UI components for stream playback.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
videoTrack | The received video stream type. | |
timeCost | int | The time elapsed, in milliseconds, from the local user joining the channel until the first video packet is received. |
onFirstAudioPacketReceived
The callback that is invoked when the first audio packet is received.
public void onFirstAudioPacketReceived(String uid, AliRtcAudioTrack track, int timeCost)This callback notifies you when the local user receives the first remote audio packet. It helps developers monitor audio link establishment speed, evaluate network quality, and optimize the user experience—for example, by displaying an “Audio connected” message or adjusting the playback policy.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
track | The received audio stream type. | |
timeCost | int | The time elapsed, in milliseconds, from the local user joining the channel until the first audio packet is received. |
onFirstRemoteAudioDecoded
This callback is invoked when the first remote audio frame is decoded.
public void onFirstRemoteAudioDecoded(String uid, AliRtcAudioTrack track, int elapsed)The callback indicates that a remote user's audio stream has been successfully decoded and is ready for playback. You can use it to monitor first-frame latency or update UI components related to playback streams.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID. |
track | The received audio stream type. | |
elapsed | int | The delay, in milliseconds, from the local user joining the channel until the first audio frame is decoded. |
onAudioAccompanyStateChanged
A callback that is invoked when the local music accompaniment playback state changes.
public void onAudioAccompanyStateChanged(AliRtcEngine.AliRtcAudioAccompanyStateCode playState, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);This callback notifies developers in real time of the current accompaniment playback status, such as started, paused, or ended, and any associated error codes. You can use this callback to monitor playback progress, handle exceptions, and update the user interface.
Parameters
Parameter | Type | Description |
playState | AliRtcEngine.AliRtcAudioAccompanyStateCode | The accompaniment playback status. |
errorCode | AliRtcEngine.AliRtcAudioAccompanyErrorCode | The playback error code, primarily for file open or decode failures. |
onRemoteAudioAccompanyStarted
This callback is invoked when a remote user starts playing audio accompaniment.
public void onRemoteAudioAccompanyStarted(String uid);This callback notifies the local application that a remote user has started playing audio accompaniment, such as background music. You can use this callback to execute initialization logic, such as updating the UI, adjusting the volume, or notifying other users.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID for whom accompaniment playback started. |
onRemoteAudioAccompanyFinished
This callback is triggered when the playback of the accompaniment from a remote user ends.
public void onRemoteAudioAccompanyFinished(String uid);This callback notifies the local application when a remote user's audio accompaniment (such as background music or sound effects) finishes playing. Developers can use this callback to execute subsequent logic (such as prompting the user or updating status).
Parameters
Parameter | Type | Description |
uid | String | The remote user ID for whom accompaniment playback finished. |
onVideoResolutionChanged
This callback is invoked when the resolution of a remote video stream changes.
public void onVideoResolutionChanged(String uid,AliRtcVideoTrack videoTrack, int width, int height);A resolution change can occur because of a camera switch, a definition adjustment, or network fluctuations. You can use this callback to dynamically adjust local video rendering logic, such as UI layout, canvas scaling, and performance optimization.
Parameters
Parameter | Type | Description |
uid | String | The remote user ID whose resolution changed. |
videoTrack | The video stream type, such as camera stream or screen stream. | |
width | int | The new video resolution width. |
height | int | The new video resolution height. |
onRtcLocalVideoStats
Publishes data statistics for the local video stream.
public void onRtcLocalVideoStats(AliRtcEngine.AliRtcLocalVideoStats aliRtcStats);This callback provides real-time statistics on local video encoding and transmission status, such as bitrate and frame rate. You can use this callback to monitor video quality, diagnose performance issues, or dynamically adjust encoding parameters.
Parameters
Parameter | Type | Description |
aliRtcStats | AliRtcEngine.AliRtcLocalVideoStats | Statistics for locally published video, including publishing bitrate, frame rate, and other information. For details, see AliRtcLocalVideoStats. |
onRtcRemoteVideoStats
This callback reports statistics for subscribed remote video streams.
public void onRtcRemoteVideoStats(AliRtcEngine.AliRtcRemoteVideoStats aliRtcStats);This callback provides real-time statistics on remote video encoding and transmission, such as bitrate, frame rate, resolution, latency, and stuttering. You can use this callback to monitor video quality, diagnose performance issues, or dynamically adjust decoding parameters.
Parameters
Parameter | Type | Description |
aliRtcStats | AliRtcEngine.AliRtcRemoteVideoStats | Statistics for pulled remote video, including remote user ID, video resolution, frame rate, stuttering count, and other information. For details, see AliRtcRemoteVideoStats. |
onRtcRemoteAudioStats
Statistics for a subscribed remote audio stream.
public void onRtcRemoteAudioStats(AliRtcEngine.AliRtcRemoteAudioStats aliRtcStats);This callback provides real-time statistics on the remote user’s audio quality, such as audio quality, packet loss rate, and latency. You can use this callback to monitor the stability of the remote audio link, diagnose network issues, and dynamically adjust playback policies, such as enabling denoising or prompting users to optimize their network.
Parameters
Parameter | Type | Description |
aliRtcStats | AliRtcEngine.AliRtcRemoteAudioStats | Statistics for pulled remote audio, including remote user ID, audio quality, packet loss rate, stuttering count, and latency. For details, see AliRtcRemoteAudioStats. |
onRtcLocalAudioStats
Publish statistics for the local audio stream.
public void onRtcLocalAudioStats(AliRtcEngine.AliRtcLocalAudioStats aliRtcStats);The callback provides real-time statistics on local audio encoding and transmission, such as bitrate, sample rate, number of sound channels, and packet loss rate. You can use this callback to monitor local audio link stability, diagnose performance issues, and dynamically adjust encoding policies—for example, by reducing the bitrate.
Parameters
Parameter | Type | Description |
aliRtcStats | AliRtcEngine.AliRtcLocalAudioStats | Statistics for locally published audio, including audio stream type, sent bitrate, sent sample rate, and number of sound channels. For details, see AliRtcLocalAudioStats. |
onAudioFocusChange
Audio focus change callback (Android platform only).
public void onAudioFocusChange(int focusChange);The SDK sends notifications when audio focus changes and automatically requests audio focus by default. If your application needs to regain audio focus, re-request it within the callback invoked by the SDK when audio focus changes.
Notification Timing
Triggered when the status of the audio output device changes (for example, plugging or unplugging headphones, switching Bluetooth devices, or switching between earpiece and speaker).
Parameters
Parameter | Type | Description |
focusChange | int | The focus state type. Values are the same as android.media.AudioManager focus type definitions. |
onAudioRouteChanged
This callback is invoked when the audio route changes. This callback is available on Android and iOS only.
public void onAudioRouteChanged(AliRtcEngine.AliRtcAudioRouteType routing);This callback notifies the application of a change in the device's audio output path, such as when a user inserts headphones or switches to the speaker. You can use this callback to dynamically adjust audio output policies, such as switching microphone modes or adjusting the volume.
Parameters
Parameter | Type | Description |
routing | AliRtcEngine.AliRtcAudioRouteType | The current audio route. |
onRemoteUserSubscribedDataChannel
Stops playback of all sound effects.
public void onRemoteUserSubscribedDataChannel(String uid);This callback is triggered when a remote user subscribes to the Data Channel. It notifies the local user that the specified remote user is ready to receive custom messages, so you can safely call sendDataChannelMsg to send data. This callback ensures reliable message delivery and prevents message loss or failure when the target user has not subscribed to the Data Channel.
This callback is triggered only in Real-time Conversational AI scenarios.
Return value
Parameter | Type | Description |
uid | String | The remote user ID. |
onDataChannelMessage
The callback invoked when a custom message is received over the data channel.
public void onDataChannelMessage(String uid, AliRtcEngine.AliRtcDataChannelMsg msg);The ARTC SDK enables you to send and receive custom messages, allowing you to transmit custom real-time message data alongside audio and video data. This callback is used to receive custom messages from the data channel. For more information, see Send and receive custom messages.
In interactive scenarios, streamers can send and receive messages, while viewers can only receive messages.
This feature is disabled by default. You can enable it by calling
setParameterwith{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}after you create the DPI engine.
Trigger Timing
After the sender calls sendDataChannelMsg to send a custom message, the receiver triggers this callback if it has enabled the data channel feature.
Parameters
Parameter | Type | Description |
uid | String | Sender user ID. |
msg | AliRtcEngine.AliRtcDataChannelMsg | The received custom message. |
onAudioVolume
The subscribed audio volume, voice state, and UID.
public void onAudioVolume(List<AliRtcEngine.AliRtcAudioVolume> speakers, int totalVolume);This callback is disabled by default and can be enabled by calling the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="d1cae8ec5dc2w">enableAudioVolumeIndication</a> interface. After you enable it, the SDK triggers this callback at the interval specified in <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="e5e0d330423ax">enableAudioVolumeIndication</a> after you join the channel, as long as users are streaming in the channel. The callback returns volume information for both local and remote speakers.
Parameter description
Parameter | Type | Description |
speakers | List<AliRtcEngine.AliRtcAudioVolume> | The array that contains the volume information of each user, including the UID, speech status, and volume.
|
totalVolume | int | The total volume after audio mixing. Valid values: 0 to 255. In the callback for a local user, totalVolume represents the mixed volume of the local user. In the callback for a remote user, totalVolume represents the total mixed volume of all speakers. |
onActiveSpeaker
You can subscribe to the person who is currently speaking.
public void OnActiveSpeaker(String uid);After you successfully call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="699faf2d18k2x">enableAudioVolumeIndication</a>, the SDK continuously monitors the audio volume of remote users and identifies the user with the loudest volume. The SDK counts how many times each remote user is identified as the loudest speaker. Within the current time period, the remote user with the highest cumulative count is considered the most active user.
Trigger Conditions
The SDK triggers this callback and reports the UID of the most active remote user when the channel contains two or more users and at least one remote user is active.
If the remote active user remains the same, the SDK will not trigger the
onActiveSpeakercallback again.If the remote active user changes, the SDK will trigger this callback again and report the UID of the new remote active user.
Parameters
Parameter | Type | Description |
uid | String | The UID of the speaker. A UID of 0 indicates the local speaker. The returned UID is for the user with the highest volume over the current time segment, not the user with the highest instantaneous volume. |
OnTestAudioVolume
This callback provides volume information during pre-call detection.
public void OnTestAudioVolume(int volume);During pre-call testing, this callback collects volume information from the device to verify the proper functioning of the local audio capture device. You can trigger this callback by calling startAudioCaptureTest.
Parameters
Parameter | Type | Description |
volume | int | Volume value. |
onCapturedAudioFrame
Callback for collecting raw data.
boolean onCapturedAudioFrame(AliRtcAudioFrame frame);This callback retrieves the raw audio data collected by the current device. It is disabled by default. To retrieve this audio data:
The
audioSourceparameter in the enableAudioFrameObserver(true, audioSource, config) call enables the current callback. You can also use theconfigparameter to set audio data properties, such as the sample rate, the number of sound channels, and the read/write mode.You can call registerAudioFrameObserver to register an audio data observer.
This operation supports configuration of the sample rate, the number of sound channels, and the read/write mode.
Call Limit
Do not perform time-consuming operations in this callback function because audio abnormalities may occur.
Parameters
Parameter | Type | Note |
frame | Audio data. |
Return Description
true: The operation succeeded.
false: Failed.
onProcessCapturedAudioFrame
Data callback after 3A
boolean onProcessCapturedAudioFrame(AliRtcAudioFrame frame);This callback provides audio data after 3A processing, but is disabled by default. To receive this audio data:
You can enable this callback by calling the enableAudioFrameObserver(true, audioSource, config) method and specifying the
audioSourceparameter. You can also use theconfigparameter to set properties such as the sample rate, the number of sound channels, and the read/write mode.You can call registerAudioFrameObserver to register an object that receives audio data.
This interface supports configuration of the sample rate, the number of sound channels, and the read-write mode.
Usage limits
You must not perform time-consuming operations in this callback function because doing so may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | The audio data. |
Return Description
true: The operation succeeded.
false: The operation failed.
onPublishAudioFrame
Streaming Audio Ingestion Callback
boolean onPublishAudioFrame(AliRtcAudioFrame frame);This callback enables you to access audio frames during stream ingest. It is disabled by default. To enable it:
You can enable this callback by calling enableAudioFrameObserver(true, audioSource, config). You can also use the
configparameter to specify the sample rate, the number of sound channels, and the read/write mode.Call registerAudioFrameObserver to register an audio frame observer.
This API lets you set the sample rate and the number of sound channels, but it only operates in read-only mode.
Usage limits
You should not perform time-consuming operations in this callback function because doing so may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | Audio data |
Return description
true: The operation succeeded.
false: The operation failed.
onPlaybackAudioFrame
Playback data callback
boolean onPlaybackAudioFrame(AliRtcAudioFrame frame);This callback retrieves playback audio data. It is disabled by default. To retrieve this audio data:
You can enable this callback by calling enableAudioFrameObserver(true, audioSource, config). The config parameter specifies the sample rate, the number of sound channels, and the read/write mode for the audio data.
You can call registerAudioFrameObserver to register the audio data receiver object.
This interface supports setting the sample rate, the number of sound channels, and the read/write mode.
Call Restrictions
You must not perform time-consuming operations in this callback function because doing so may cause audio abnormalities.
Parameters
Parameter | Type | Description |
frame | AliRtcAudioFrame | Audio data. |
Return Description
true: Success.
false: Failure.
onRemoteUserAudioFrame
The callback for data pulled from a remote user.
boolean onRemoteUserAudioFrame(String uid, AliRtcAudioFrame frame);This callback retrieves remote audio data for a specified user. This feature is disabled by default. To retrieve this audio data:
You can enable the current callback by specifying the
audioSourceparameter in enableAudioFrameObserver(true, audioSource, config). Additionally, theconfigparameter lets you configure the sample rate and the number of sound channels for retrieving audio data, along with the read/write mode.You can call registerAudioFrameObserver to register an audio data observer.
This operation does not support setting the sample rate or the number of sound channels, but does support setting the read-write pattern.
Invocation Limits
Avoid performing any time-consuming operations in this callback function because doing so may cause audio abnormalities.
Parameters
Parameter | Type | Description |
uid | String | User ID. |
frame | Audio data. |
Return Description
true: The operation succeeded.
false: The operation failed.
OnDestroyCompletion
This is the callback for engine destruction completion.
void OnDestroyCompletion();This callback indicates that the SDK engine instance has been destroyed. You can now create a new instance.
Trigger Condition
This callback is triggered after you call the destroy method.
onTextureCreate
Callback for OpenGL context creation.
void onTextureCreate(long context);This callback is triggered when the internal OpenGL context in the SDK is created.
Trigger Conditions
This callback is triggered when the internal OpenGL context in the SDK is created, and you can initialize related resources.
Parameter Description
Parameter | Type | Description |
context | long | OpenGL context. |
onTextureUpdate
This is a callback for updating OpenGL textures.
int onTextureUpdate(int textureId, int width, int height, AliRtcVideoSample videoSample);Trigger Conditions
This callback is triggered after each video frame is uploaded to an OpenGL texture. If you register an external OpenGL texture data observer, you can process the texture and return the ID of the processed texture in this callback.
Parameter description
Parameter | Type | Description |
textureId | int | The OpenGL context. |
width | int | The video width. |
height | int | The video height. |
videoSample | The video frame data. |
Return Description
The method returns a new texture ID or an existing texture ID. If the returned value is less than 0, the texture ID is not updated.
onTextureDestroy
void onTextureDestroy();Trigger Condition
This callback is triggered when the SDK destroys its internal OpenGL context, allowing you to clean up relevant resources.
onLocalVideoSample
Callback for locally captured video data.
public boolean onLocalVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);This callback provides raw local video frames—such as YUV data—captured from the local camera. You can use it to implement custom video processing logic, such as applying filters, adding watermarks, or transcoding. You also determine whether to return the processed data to the SDK for encoding or rendering. Return true to send the processed video to the SDK.
When it triggers
After you successfully invoke <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="22a5a6bd53c77">registerVideoSampleObserver</a> to register a video data observer, the SDK captures the corresponding video frames.
Parameter Description
Parameter | Type | Description |
sourceType | The video source type. | |
videoSample | The video data. |
Return value
true: Write the processed data back to the SDK. This is the default behavior. You must return true if you modify AliRtcVideoSample.data.
false: Do not write back to the SDK. Use this when you directly modify AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, or AliRtcVideoSample.dataFrameV.
onPreEncodeVideoSample
You can subscribe to a callback for video data before local encoding.
public boolean onPreEncodeVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoRawData);This interface is a callback for retrieving raw video data before local video encoding, enabling you to access the original video data—such as YUV data—before the SDK encodes video frames. You can use this callback to implement custom processing logic, such as adding watermarks, adjusting colors, or transcoding, and decide whether to return the processed data to the SDK for subsequent encoding.
Parameters
Parameter | Type | Description |
sourceType | Video stream type | |
videoRawData | Video raw data |
Return Description
true: Write the data back to the SDK. This is the default behavior. You must write the data back when you modify AliRtcVideoSample.data.
false: Do not write the data back to the SDK. Use this setting when you directly modify AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, or AliRtcVideoSample.dataFrameV.
onRemoteVideoSample
Callback for subscribed remote video data.
public boolean onRemoteVideoSample(String callId,AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);This interface is a callback for retrieving subscribed remote video data. It provides raw video frame data from remote users in formats such as YUV. You can use this callback to implement custom processing logic, such as applying filters, adding watermarks, or transcoding. You can then decide whether to return the processed data to the SDK for subsequent rendering.
Parameters
Parameter | Type | Description |
callId | String | User ID |
sourceType | Video stream type | |
videoSample | Raw video data |
Return description
-
true: Writes the data back to the SDK. This is the default behavior. You must use this option when you operate on AliRtcVideoSample.data.
-
false: Does not write the data back to the SDK. Use this option when you need to directly operate on AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV.
onGetVideoFormatPreference
Video Data Output Format
public AliRtcVideoFormat onGetVideoFormatPreference();Return Description
The expected video output format.
onGetObservedFramePosition
Video output content.
public int onGetObservedFramePosition();This callback retrieves the content or type of video data output. Developers can use it to determine the processing stage of video frames output by the SDK, such as after capture, before encoding, or after stream pulling.
0 indicates success. Other values indicate failure.
The desired video output content is an enumeration value of the AliRtcVideoObserPosition type, representing captured data, pulled stream data, or pre-encoding data.
onPublishLiveStreamStateChanged
This callback is invoked when the status of relayed live streaming changes.
public void onPublishLiveStreamStateChanged(String streamUrl, AliRtcLiveTranscodingState state, AliEngineLiveTranscodingErrorCode errorCode);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL. |
state | The state of bypass live streaming. | |
errorCode | The error code. |
onPublishTaskStateChanged
This callback is invoked when the status of a relayed live streaming task changes.
public void onPublishTaskStateChanged(String streamUrl, AliRtcTrascodingPublishTaskStatus state);Parameters
Parameter | Type | Description |
streamUrl | String | The ingest URL. |
state | The status of the bypass live streaming task. |
onNetworkQualityChanged
Network quality change callback.
public void onNetworkQualityChanged(String uid, AliRtcNetworkQuality upQuality, AliRtcNetworkQuality downQuality);Parameters
Parameter | Type | Description |
uid | String | The user ID. An empty value indicates the local user's upload and download network status. |
upQuality | The quality of the upstream network. | |
downQuality | Status of the downstream network. |
onNetworkQualityProbeTest
The network quality detection callback is provided approximately 3 seconds after detection starts.
public void onNetworkQualityProbeTest(AliRtcNetworkQuality quality){}Parameters
Parameter | Type | Description |
quality | Network quality. |
onNetworkQualityProbeTestResult
This callback reports the results of the network quality probe. It is triggered after about 30 seconds of probing.
public void onNetworkQualityProbeTestResult(int code, AliRtcEngine.AlirtcNetworkQualityProbeResult result){}Parameters
Parameter | Type | Description |
code | int | The return value. 0 indicates a successful probe. -1 indicates the probe failed due to a poor network connection. |
result | The network quality. |
onSnapshotComplete
Snapshot result callback interface.
public void onSnapshotComplete(String userId, AliRtcVideoTrack trackType, Bitmap bitmap, boolean success)This API returns the result and details of a screenshot.
Parameters
Parameter | Type | Description |
userId | String | User ID |
trackType | The video stream type for screenshots. | |
bitmap | Bitmap | Screenshot data. |
success | boolean | Whether the screenshot was successful. |
onScreenSharePublishStateChanged
Callback for screen sharing stream ingest changes.
public void onScreenSharePublishStateChanged(AliRtcEngine.AliRtcPublishState oldState , AliRtcEngine.AliRtcPublishState newState, int elapseSinceLastState, String channel)This callback triggers a notification when the screen sharing stream ingest status changes.
Parameters
Parameter | Type | Description |
oldState | AliRtcEngine.AliRtcPublishState | Old state before stream ingest status change. |
newState | AliRtcEngine.AliRtcPublishState | The new stream ingest state. |
elapseSinceLastState | int | Status change interval (milliseconds). |
channel | String | Name of the channel to which the resource currently belongs. |
onScreenShareSubscribeStateChanged
Callback triggered when the subscription status of the screen sharing stream changes.
public void onScreenShareSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback notifies you when the subscription status of the current user to a remote user's screen sharing stream changes.
Metric description
Parameters | Type | Description |
uid | String | Remote user ID. |
oldState | AliRtcEngine.AliRtcSubscribeState | Previous subscription state. |
newState | AliRtcEngine.AliRtcSubscribeState | Current subscription state. |
elapseSinceLastState | int | Time interval (milliseconds) since the last state change. |
channel | String | Current channel. |
onOccurError
Fault notifications
public void onOccurError(int error, String message);The global error notification callback for the ARTC SDK informs the application layer when a critical fault occurs in the SDK's internal engine. You can use this callback to obtain the error code and error message for exception handling, log recording, or user prompts.
Parameter description
Parameter | Type | Description |
error | int | The error type. See the list of error codes. |
message | String | The error message. |
OnLocalAudioStateChanged
Callback for the status of the local audio device.
public void OnLocalAudioStateChanged(int state);This callback is triggered when the state of the local audio capture device changes, such as when you call startAudioCapture or stopAudioCapture.
Parameters
Parameter | Type | Description |
State | int |
|
setParameter
Configure custom parameters
public abstract int setParameter(String param);Parameters
Parameter | Type | Description |
param | String | The custom parameter. |
getParameter
Retrieve custom parameters.
public abstract String getParameter(String param);Parameters
Parameter | Type | Description |
param | String | The custom parameter. |
registerAudioVolumeObserver
Registers an object to receive audio volume data.
public abstract void registerAudioVolumeObserver(AliRtcAudioVolumeObserver observer);Call this interface to register the object. To cancel the registration, call unRegisterAudioVolumeObserver.
Invocation timing
To obtain volume information, you must call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="85a734d2596vf">enableAudioVolumeIndication</a>to set the callback frequency and smoothing coefficient, and then call this interface to register the receiver object.When you perform a pre-call audio device detection by calling
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ae07dc986abf3" id="29e92857a5iv8">startAudioCaptureTest</a>, you can call this interface and implement the<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e375c31bdez6j" id="e5cb797b7cg5p">OnTestAudioVolume</a>callback.
Metric description
Parameter | Type | Description |
observer | The object that receives volume data. |
unRegisterAudioVolumeObserver
Deregisters a volume export object.
public abstract void unRegisterAudioVolumeObserver();This method deregisters the volume data output object and is the counterpart to registerAudioVolumeObserver.
When to Call
Call this method to deregister the audio data receiver object after you register it with registerAudioVolumeObserver.
enableAudioFrameObserver
You can set audio callback parameters.
public abstract int enableAudioFrameObserver(boolean enable, AliRtcAudioSource audioSource, AliRtcAudioFrameObserverConfig config);This method enables or disables audio data callbacks for a specified type, allowing developers to retrieve various raw and encoded audio data. It is disabled by default. To enable it, call this method.
When enabling audio data callbacks for a specific AliRtcAudioSource, you must also call registerAudioFrameObserver to provide the audio data receiver object.
When to call
Call this method when you need to retrieve audio data.
Parameters
Parameter | Type | Description |
enable | boolean | Whether to allow audio data callbacks. |
audioSource | The callback data source type, including post-capture (0), post-3A (1), ingest (2), playback (3), post-ingest/playback mix (4), and pulled audio data (5). Note
| |
config | Audio callback parameter settings, including sample rate, number of sound channels, and callback read/write mode (read-only, write-only, read-write). If null, defaults to (48000, 1, ReadOnly). |
Return value
0: The operation was successful.
<0: The operation failed.
registerAudioFrameObserver
Registers an audio data callback.
public abstract void registerAudioFrameObserver(AliRtcAudioFrameObserver observer);This method registers the receiver object to receive audio callback data.
When to call
Call this method when you need the SDK to trigger onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, or onRemoteUserAudioFrame to retrieve various types of audio data. To deregister, call this method again with null.
Limitations
You must call enableAudioFrameObserver to enable the callback for the specific AliRtcAudioSource. Otherwise, the provided observer will not receive data.
Parameters
Parameter | Type | Description |
observer | The audio data callback receiver object instance. Pass null to deregister. |
registerVideoSampleObserver
Registers an object for exporting video data.
public abstract void registerVideoSampleObserver(AliVideoObserver observer);This method registers an object to export video data. Call unRegisterVideoSampleObserver to unregister the object.
When to call
To obtain raw video data (such as YUV or RGBA format), call this method to register a video data observer to obtain video data at various stages. AliRtcVideoObserver is the video data observer class.
Related callbacks
After you successfully register a video data output observer, the SDK triggers the callbacks you implemented in the AliRtcVideoObserver interface for each captured video frame. Implement the appropriate callbacks based on your business needs:
onLocalVideoSample: A callback that delivers locally captured video data.
onRemoteVideoSample: A callback that delivers remote video data.
onPreEncodeVideoSample: A callback that delivers local video data before encoding.
Parameters
Parameter | Type | Description |
observer | The video data output object. |
Return Description
The AliVideoObserver callback returns the output data.
unRegisterVideoSampleObserver
Deregisters an object that exports video data.
public abstract void unRegisterVideoSampleObserver();This interface corresponds to the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="dcf635790da7v">registerVideoSampleObserver</a> interface and is used to deregister the object that exports video data.
registerLocalVideoTextureObserver
Registers an observer for OpenGL texture data from the local camera track.
public abstract void registerLocalVideoTextureObserver(AliTextureObserver observer);If you want to obtain raw video data, call the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="4f1f5a423ch4j">registerVideoSampleObserver</a> interface to register a video data callback. If you want to obtain internal texture data, call this interface. To unregister the observer, call the unRegisterLocalVideoTextureObserver interface.
This method applies only to the local camera stream.
Related callbacks
After you successfully register the observer for the local camera stream’s video OpenGL texture data, the SDK triggers the callbacks that you implemented in the AliRtcTextureObserver interface for each captured video frame. Implement the corresponding callbacks as needed:
onTextureCreate: This callback is triggered when the SDK creates its internal OpenGL context.
onTextureUpdate: This callback is triggered after each video frame is uploaded to the OpenGL texture. If an external OpenGL texture data observer is registered, you can process the texture in this callback and return the processed texture ID. This callback must return a valid texture ID. If you do not process the texture, you must return the textureId parameter.
onTextureDestroy: This callback is triggered when the SDK's internal OpenGL context is destroyed.
Parameters
Parameter | Type | Description |
observer | The OpenGL texture data observer. |
Return Instructions
Output data is returned through the AliVideoObserver callback.
unRegisterLocalVideoTextureObserver
Deregisters the observer for OpenGL texture data from the local camera track.
public abstract void unRegisterLocalVideoTextureObserver();This method corresponds to registerLocalVideoTextureObserver and removes the registered observer.
snapshotVideo
Takes a screenshot of a video stream.
public abstract int snapshotVideo(String userId, AliRtcVideoTrack trackType);You can call this method to take a screenshot of a specified user's video stream.
Limitations
This is an asynchronous operation. A return value of 0 indicates that the method call succeeded, but the SDK has not yet taken the screenshot.
Related callbacks
After you successfully call this method, listen for the onSnapshotComplete callback to retrieve the screenshot result and details.
Parameters
Parameter | Type | Description |
userId | String | The user ID. If null or empty, a screenshot of the local user is taken. |
trackType | The video stream type to capture. Only supports:
|
Return instructions
0: The method call succeeded. The screenshot result is provided by the onSnapshotComplete callback.
A non-zero value: The operation failed. Returns an error code.
setLogDirPath
Sets the path for storing SDK log files.
public static int setLogDirPath(String logDirPath);Parameters
Parameter | Type | Description |
logDirPath | String | The absolute path for storing log files. Default: app directory. |
Return Description
A return value of 0 indicates success. Non-zero values indicate failure. Note: To avoid log loss, call this method before any other SDK methods. Ensure that the specified path exists and is writable.
setLogLevel
Sets the logging level.
public static void setLogLevel(AliRtcLogLevel logLevel);Parameters
Parameter | Type | Description |
logLevel | The log level. |
setDeviceOrientationMode
Sets the device orientation mode, which affects how video is displayed.
public abstract void setDeviceOrientationMode(AliRtcOrientationMode mode);This method sets the device orientation mode, which affects how video is displayed.
Limitations
This method is supported only on Android and iOS.
Parameters
Parameter | Type | Description |
mode | AliRtcOrientationMode | The device orientation. |
Return Description
None.
requestAudioFocus
Requests audio focus.
public abstract int requestAudioFocus();When to call
The SDK requests audio focus internally at startup. Generally, you do not need to request it actively. If you have previously called abandonAudioFocus, you can call this method to regain audio focus.
Limitations
For Android only.
Parameters
None.
Return value
0: failed.
1: successful.
abandonAudioFocus
Release audio focus.
public abstract int abandonAudioFocus();When to call
The SDK internally calls this method to release audio focus during teardown. In some scenarios, you may need to release audio focus actively. After releasing audio focus, some devices may have no sound or low volume. To restore the audio, call requestAudioFocus.
Limitations
For Android only.
Return description
0: The operation failed.
1: The operation was successful.
getNetworkTime
Queries the current network time.
public abstract long getNetworkTime();This method retrieves the current Network Time Protocol (NTP) time, in milliseconds, calibrated for time offset.
When to call
You can call this method when synchronizing multi-end behaviors to obtain a synchronized network time baseline for calibrating the current time.
Return information
The current Network Time Protocol (NTP) time, in milliseconds.
sendDataChannelMsg
Sends a custom message over the data channel.
public abstract int sendDataChannelMsg(AliRtcDataChannelMsg Msg);The ARTC SDK supports sending and receiving custom messages, enabling you to transmit real-time message data alongside audio and video streams. Use this method to send real-time control commands, state synchronization data, or other business-related messages. For usage details, see Custom Message Sending and Receiving.
The custom message channel is disabled by default. To use this feature, call the
setParameterAPI with `"{\"data\":{\"enablePubDataChannel\":true,\"enableSubDataChannel\":true}}"` to enable it. You can enable this feature either before or after joining a channel.Messages can contain any data, such as text.
Related callbacks
After the sender successfully enables the custom message channel, they can call this method to send custom messages. The receiver obtains them through the onDataChannelMessage callback.
Limitations
Streamers can send and receive messages. Viewers can only receive messages.
You must call setParameter to enable the custom message channel.
Data sending is subject to the following limits:
A maximum bitrate of 30 KB/s.
Up to 60 packets per second, with each packet up to 1 KB in size.
Parameters
Parameter | Type | Description |
Msg | The message content. |
Return instructions
0: Success.
Non-zero: Failure. Returns an error code.
startScreenShare
This method is deprecated. We recommend that you use the new startScreenShare method instead.
You can start sharing the screen and audio stream.
public abstract int startScreenShare(Intent intent);Parameters
Name | Description |
intent | An externally created Activity to start screen sharing. If not created externally, pass null. We recommend passing null. |
Return value
0: successful.
Other values: failed.
startScreenShare
This method will be phased out. We recommend using the new startScreenShare method.
Starts screen sharing.
public abstract int startScreenShare();Return value
0: Successful.
Other values: Failed.
startScreenShare
Starts ingesting a screen-sharing video stream.
public abstract int startScreenShare(Intent intent, AliRtcScreenShareMode screenShareMode);Parameters
Name | Description |
intent | An externally created Activity to start screen sharing. If not created externally, pass null. We recommend passing null. |
screenShareMode | The screen-sharing type. For details, see AliRtcScreenShareMode. |
Return value
0: Success.
Other values: Failure.
stopScreenShare
Stops sharing the screen and the accompanying audio stream.
public abstract int stopScreenShare();Return value
0: The method call succeeded.
Other values: The method call failed.
setAudioShareVolume
Sets the volume of the shared audio stream.
public abstract int setAudioShareVolume(int volume);Parameters
Name | Description |
volume | The volume level. Valid range: [0, 100]. Default: 50. |
Return value
0: The method call was successful.
Other values: The method call failed.
isScreenSharePublished
Determines whether a screen-sharing stream is being ingested.
public abstract boolean isScreenSharePublished();Return value
true: A screen-sharing stream is being ingested.
false: No screen-sharing stream is being ingested.
setScreenShareEncoderConfiguration
Sets the video encoding properties for screen-sharing streams.
public abstract void setScreenShareEncoderConfiguration(AliRtcScreenShareEncoderConfiguration config);This method configures video parameters for screen-sharing stream encoding, such as resolution, frame rate, bitrate, and video orientation.
All parameters have defined range limits. If a parameter falls outside the valid range, the SDK automatically adjusts it. As a result, the actual configuration may differ from your specified settings.
When to call
You can call this method before or after joining a channel. If you only need to configure screen-sharing stream video encoding properties once per session, we recommend calling it before joining the channel.
Parameters
Parameter | Type | Description |
config | Predefined screen-sharing encoding properties, such as resolution, frame rate, bitrate, and video orientation. |
setGlobalEnvironment
Sets the global environment.
public int setGlobalEnvironment(GlobalEnv env);This method specifies the SDK’s global operating environment, which primarily determines where log uploads and instrumentation data are sent:
When set to the Chinese mainland environment, logs and instrumentation data are uploaded to data centers in the Chinese mainland.
When set to an overseas environment, data is routed to data centers outside China, such as Singapore.
When to call
You can call this method early in the application’s initialization—for example, in the Application’s onCreate() method.
Limitations
This setting is global and must be called only once.
Multiple calls overwrite previous settings and may affect established connections or session states. Do not switch dynamically during runtime.
Example
AlivcEnv.GlobalEnv env = ENV_DEFAULT; // For overseas, use ENV_SEA
AlivcBase.getEnvironmentManager().setGlobalEnvironment(env);Parameters
Parameter | Type | Description |
env |
| Specifies the global environment. Supported enumeration values: |
Return value
Returns an int result code:
0: indicates success.A non-
0value indicates failure.