This topic describes the APIs in the ApsaraVideo Real-time Communication SDK for Android.
Contents
Basic interfaces
|
API |
Description |
|
Create an AliRtcEngine instance using the singleton pattern. | |
|
Create an AliRtcEngine instance (singleton pattern). | |
|
Destroys an AliRtcEngine object. | |
|
Destroy the AliRtcEngine object. | |
|
Enable HTML5 compatibility mode. | |
|
Check whether the current environment is compatible with HTML5. | |
|
Sets a listener for local user behavior callback events. | |
|
Sets a listener for notification events about remote user behavior. | |
|
Query the current SDK version. |
Channel-related methods
|
API |
Description |
|
Sets the channel mode. | |
|
Sets the audio encoding and scenario modes. | |
|
Queries whether the audio-only mode is enabled. | |
|
Set to audio-only mode or audio-video mode. | |
|
Join a channel. | |
|
Join a channel. | |
|
Join the channel. | |
|
Leaves a channel. | |
|
Checks whether you are in a channel. | |
|
Set the user role. | |
|
Get the user role. | |
|
Refreshes the authentication information. | |
|
Refresh the authentication information. |
Publishing and subscription-related methods
|
API |
Description |
|
Stops or resumes publishing the local video stream. Publishing is enabled by default. | |
|
Queries whether an audio stream is published. | |
|
Specifies whether to subscribe to the audio tracks of remote users. By default, all remote audio tracks are subscribed to. Call this method before joining the channel. | |
|
Stops or resumes pulling the audio stream of a specific remote user. | |
|
Stop or resume receiving audio streams from all remote users. | |
Whether to push the local video stream. The SDK pushes by default. | |
|
Queries whether a video stream is published. | |
|
Specifies whether to subscribe to the video streams of remote users. By default, all remote video streams are subscribed to. Call this method before joining a channel. | |
|
Stop or resume subscribing to specified remote video streams. | |
|
Stop or resume receiving all remote video streams. | |
|
Subscribes to or stops subscribing to the media stream of a specific remote user. Call this method when both audio and video tracks are available and require management. | |
|
Stop or resume a specific remote user's media stream. Use this API when both audio and video are present and require control. | |
|
Stop or resume the media stream of a specific remote user across channels. | |
|
Stop or resume stream subscriptions for all users across channels. | |
|
Adjust the stream pulling playback volume. |
Methods related to audio device management
|
API |
Description |
|
Specifies whether to stop publishing local audio. | |
|
Set whether to stop playback of the remote audio stream. | |
|
Stop or resume all remote audio playback. | |
|
Start audio collection. | |
|
Starts audio collection. | |
|
Shut down audio capture. | |
|
Set the default audio output device. | |
|
Set audio output to the earpiece or speaker. | |
|
Queries whether the current audio output device is the earpiece or the speaker. | |
|
Enable volume detection. | |
|
Enable in-ear monitoring. | |
|
Set in-ear monitoring volume. | |
|
Turn on the audio playback device. | |
|
Shut down the audio playback device. | |
|
Set the local playback volume. | |
|
Set the recording volume. | |
|
Play audio files. | |
|
Stop audio file playback. | |
|
Enable audio capture device detection before a call. | |
|
Shut down audio capture detection. |
Methods related to voice change and reverberation
|
API |
Description |
|
Set voice change sound effect mode. | |
|
Set the pitch parameter. | |
|
Set the reverberation mode. | |
|
Sets the reverberation mode and its parameters. | |
|
Set a preset voice enhancement sound effect pattern. | |
|
Set the audio equalizer (EQ) parameters to adjust the gain of a specified frequency band. |
Custom audio input
|
API |
Description |
|
Add an external audio stream. | |
|
Inputs external audio stream data. | |
|
Sets the volume of external audio for stream ingest. | |
|
Queries the volume of external audio for stream ingest. | |
|
Sets the playback volume of the external audio stream. | |
|
Gets the playback volume of the external audio stream. | |
|
Delete the external audio stream. |
Music accompaniment
|
API |
Feature description |
|
Get audio file information. | |
|
Start accompaniment mixing. | |
|
Stop accompaniment mixing. | |
|
Sets the volume of the accompaniment for both local playback and stream ingest. | |
|
Set the accompaniment volume for stream ingest. | |
|
Get accompaniment stream ingest volume. | |
|
Set the local playback volume of the accompaniment. | |
|
Get local accompaniment playback volume. | |
|
Pause the accompaniment mixing. | |
|
Restart accompaniment mixing. | |
|
Get the duration of the accompaniment file, in milliseconds. | |
|
Get the playback progress of the accompaniment file, in milliseconds. | |
|
Set the playback position of the accompaniment file. |
Sound Effect File
|
API |
Description |
|
Preloads a sound effect. | |
|
Deletes a preloaded sound effect file. | |
|
Starts the playback of a sound effect. | |
|
Stops the playback of a sound effect. | |
|
Stops the playback of all sound effects. | |
|
Pauses the playback of a sound effect. | |
|
Pauses the playback of all sound effects. | |
|
Resumes the playback of a sound effect. | |
|
Restore all sound effect files. | |
|
Set the volume of a sound effect for stream ingest. | |
|
Gets the mixing volume of a sound effect for stream ingest. | |
|
Set the volume of all sound effects for stream ingest. | |
|
Set the volume of a sound effect for local playback. | |
|
Query the volume of a sound effect for local playback. | |
|
Sets the volume of all sound effects for local playback. |
Record audio and video files
|
API |
Feature description |
|
Record audio and video files (aac, wav, mp4). | |
|
Stop recording audio/video files. |
Methods related to video device management
|
API |
Description |
|
Creates a SurfaceView rendering view. | |
|
Sets the rendering window and drawing parameters for the local preview. | |
|
Set the rendering window and drawing parameters for the remote video. | |
|
Set the camera collection preferences. | |
|
Disables or re-enables local video capture. | |
|
Specifies whether to stop publishing a local video stream. | |
|
Check whether the camera is turned on. | |
|
Set video encoding properties. | |
|
Set video decoding properties | |
|
Switches between the front and rear cameras. By default, the front camera is used. | |
|
Queries the current camera direction. | |
|
Start a local preview. | |
|
Stops a local preview. | |
|
Set the camera scaling ratio. | |
|
Gets the maximum zoom ratio of the camera. | |
|
Gets the current camera scaling setting. | |
|
Set the camera exposure. | |
|
Get the camera exposure. | |
|
Gets the minimum exposure supported by the camera. | |
|
Gets the maximum exposure supported by the camera. | |
|
Set the camera flash toggle. | |
|
Indicates whether the device supports manual focus. | |
|
Set the camera's manual focus point. | |
|
Specifies whether the camera supports setting an exposure point. | |
|
Set the camera exposure point. | |
|
Specifies whether the camera automatically focuses on faces. | |
|
Set camera face focus. | |
|
Set video mirroring for preview and stream ingest. | |
|
Set video capture scaling timing. |
Methods related to video data callbacks
|
API |
Feature description |
|
Registers the video data output object. | |
|
Unregister the video data output object. | |
|
Register an observer for local camera video stream OpenGL texture data. | |
|
Cancel the registration of the OpenGL texture data observer for the local camera stream video. | |
|
Video screenshot feature. |
Methods related to audio data callbacks
|
API |
Feature Description |
|
Register volume data output object. | |
|
Cancel the registration of the volume data Outputs object. | |
|
Set the audio callback parameters. | |
|
Register the audio data callback. |
Custom video input
|
API |
Description |
|
Enables an external video input source. | |
|
Imports external video data. |
Methods related to screen sharing
|
API |
Feature description |
|
Enable screen sharing stream ingest. | |
|
Start sharing screen and audio stream. Note
This interface will be deprecated soon. | |
|
Start screen sharing. Note
This API will be deprecated soon. | |
|
Stop the screen sharing stream. | |
|
Set the shared audio stream volume. | |
|
Queries whether to push screen sharing. | |
|
Set screen stream video encoding properties. |
Live Streaming Bypass Interface
|
API |
Description |
|
Start relayed live streaming. | |
|
Update the parameters for relayed live streaming. | |
|
Stops bypass live streaming. | |
|
Query the status of relayed live streaming. |
Network quality probe API
|
API |
Description |
|
Start network quality testing. | |
|
Stops network quality testing. |
SEI
|
API |
Feature description |
|
Push SEI stream. | |
|
Push SEI stream (extension). |
Other APIs
|
API |
Description |
|
Sets custom parameters. | |
|
Get custom parameters | |
|
Sets the storage path for SDK log files. | |
|
Sets the log level. | |
|
Set the device orientation. | |
|
Request audio focus. | |
|
Release audio focus. | |
|
Get the current network time. | |
|
Send data channel custom messages. |
AliveEnv methods
|
API |
Feature description |
|
Set global environment. |
Callbacks
AliRtcEngineEventListener
|
API |
Feature description |
|
Network connection status callback. Pay attention to this callback. | |
|
Callback for on-premises device abnormalities. Customers must handle this callback. | |
|
Callback for the result of joining a channel. | |
|
Result callback for leaving a channel. | |
|
Callback for changes in audio stream ingest. | |
|
Callback for audio subscription status changes. | |
|
Video stream ingest change callback. | |
|
Callback for camera stream subscription changes. | |
|
Bypass stream ingest status change callback. | |
|
A callback for when the status of a bypass task changes. | |
|
Network quality change callback. | |
|
Callback for network quality detection. This callback is triggered about 3 seconds after detection starts. | |
|
Callback for network quality detection results. This callback is provided about 30 seconds after detection starts. | |
|
Screenshot result callback interface. | |
|
Callback for screen sharing stream ingest changes. | |
|
Callback for changes to screen sharing stream subscriptions. | |
|
Fault notification. | |
|
Local audio device status callback. |
AliRtcEngineNotify
|
API |
Feature description |
|
This notification indicates that the user authentication will expire in 30 seconds. The customer must handle this callback. | |
|
The user calls an interface that requires authentication, and the server-side returns expired information. | |
|
Remote user offline notification | |
|
Remote user online notification. | |
|
Notifications for remote stream ingest. | |
|
Message that you were kicked from the server or the meeting channel was closed. | |
|
Notification that a remote user is muted. | |
|
An audio device interrupts the start notification. | |
|
Audio device interruption completion notification. | |
|
The peer user sends a notification about video black frame data. | |
|
Sends a notification when the peer user shuts down camera stream capture. | |
|
Remote user application moves to the background. | |
|
Remote user application returns to the foreground. | |
|
Local sound effect playback ended callback | |
|
Audio file information callback. | |
|
Receive a callback with media extension information. | |
|
This message triggers when the first video frame appears for a remote user. | |
|
This message triggers when the preview starts displaying the first video frame. | |
|
Callback for receiving the first video frame from a remote user. | |
|
Callback for when the first video package is sent. | |
|
First audio package sent callback. | |
|
Callback for receiving the first video package. | |
|
Audio first packet acceptance callback. | |
|
Callback for the first decoded remote audio frame. | |
|
Local accompaniment playback status callback. | |
|
Remote user accompaniment playback starts. | |
|
Remote user accompaniment playback end callback. | |
|
Real-time data callback (triggers every 2 seconds). | |
|
Publish data statistics for the local video stream (triggered every 2 seconds). | |
|
Subscribe to remote video stream data statistics (triggered every 2 seconds). | |
|
Data statistics for the subscribed remote audio stream (triggered every 2 s). | |
|
Data statistics for the published local audio stream. Triggered every 2 s. | |
|
Audio focus change callback (Android only). | |
Callback for audio routing changes (applies only to Android and iOS platforms). | |
This callback is triggered when you can start sending data channel messages. | |
|
Data channel custom message receiving callback. |
AliRtcAudioVolumeObserver
|
API |
Feature description |
|
Callback for user volume indications. | |
|
Voice activation detects active user callback. | |
|
A callback for volume information during the pre-call check. |
AliRtcAudioFrameObserver
|
API |
Feature description |
|
Audio capture raw data callback. | |
|
Audio data callback after 3A processing. | |
|
Audio data callback for stream ingest. | |
|
Playback data callback. | |
|
Callback for remote stream pulling data. |
AliRtcDestroyCompletionObserver
|
API |
Feature description |
|
DPI engine destroy complete callback. |
AliRtcTextureObserver
|
API |
Feature Description |
|
OpenGL context creation callback. | |
|
OpenGL texture update callback. | |
|
OpenGL context destroy callback. |
AliRtcVideoObserver
|
API |
Feature Description |
|
Subscribed locally captured video data callback. | |
|
Callback for pre-encoded local video data from a subscription. | |
|
Callback for subscribed remote video data. | |
|
Video data output format | |
|
Video data outputs. |
Details
getInstance[1/2]
You can obtain a singleton instance of AliRtcEngine.
public static AliRtcEngineImpl getInstance(Context context);This method and getInstance[2/2] both create AliRtcEngine instances. The difference is that
getInstance[2/2]supports additional configuration during 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 the AliRtcEngine instance (singleton pattern).
public static AliRtcEngineImpl getInstance(Context context, String extras);Both 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 create an AliRtcEngine instance. The difference is that this method lets you specify additional configurations during 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. |
|
extras |
String |
Specifies a JSON configuration for setting special features of the software development kit (SDK) during canary releases. This can be an empty string. |
Return Description
Returns a singleton instance of the AliRtcEngineImpl class, which is a subclass of AliRtcEngine.
destroy[1/2]
Destroys an AliRtcEngine instance.
public abstract void destroy();Destroys the singleton AliRtcEngine instance. After calling this method, all internal resources are released. You cannot use any other AliRtcEngine methods or callbacks. To reuse the engine, 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]lets you pass a completion observer.If you want to create a new AliRtcEngine instance after destruction, make sure to do so only after this method completes.
When to call
We recommend calling this method after real-time communication ends—that is, when you no longer need AliRtcEngine functionality—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 instance.
public abstract void destroy(AliRtcDestroyCompletionObserver observer);Destroys the singleton AliRtcEngine instance. After calling this method, all internal resources are released. You cannot use any other AliRtcEngine methods or callbacks. To reuse the engine, call getInstance to create a new instance.
This method is an asynchronous invocation that provides an observer for developers to track destruction completion. You can perform the next creation only after OnDestroyCompletion completes, and destruction cannot be completed before the observer callback executes.
When to call
We recommend calling this method after real-time communication ends to release the instance.
Limitations
To avoid deadlocks, do not call this method from within any SDK callback.
Related callback
After the SDK engine object is destroyed, it triggers the OnDestroyCompletion callback, indicating that a new creation can be performed.
Parameters
|
Parameter |
Type |
Description |
|
observer |
Notification callback for engine destruction. Listen for this callback to ensure resources are fully released. |
setH5CompatibleMode
Specifies whether to enable HTML5 compatibility mode.
public static int setH5CompatibleMode(int enable);Parameters
|
Parameter |
Type |
Description |
|
enable |
int |
Specifies whether to enable the HTML5 compatibility mode. Valid values:
|
You cannot modify the HTML5 compatibility settings for the current version after creating an AliRtcEngine instance. You must call this method before creating the instance.
getH5CompatibleMode
Queries whether HTML5 compatibility mode is enabled.
public static int getH5CompatibleMode();Response description
A value of 1 indicates that HTML5 compatibility mode is enabled.
A value of 0 indicates that HTML5 compatibility mode is disabled.
setRtcEngineEventListener
Sets a listener to receive callback events for the local user.
public abstract void setRtcEngineEventListener(AliRtcEngineEventListener listener);This method sets up event callbacks related to the local user, such as the result of joining or leaving a channel, user role changes, audio and video stream ingest status changes, audio and video stream subscription status changes, network quality changes and probe results, screenshot results, device status and exceptions, and SDK errors. Developers implement these callback methods to handle the lifecycle and state changes of the local user in RTC applications.
All callbacks have empty default implementations. You do not need to implement all callbacks. Implement only those relevant to your business needs.
To implement callbacks related to remote users, first frames, first packets, sound effects, audio accompaniment, or authentication, implement the
AliRtcEngineNotifyclass and callsetRtcEngineNotify.Avoid performing time-consuming operations in callbacks, such as calling the destroy method. Doing so may cause blocking and affect SDK performance.
When to call
Call this method before joining a channel.
Related callbacks
When exceptions occur, the SDK first attempts internal retries to recover automatically. If recovery fails, the SDK notifies your application through predefined callbacks. Below are key callbacks that require application-level handling:
|
Causes of abnormality |
Callbacks and parameters |
Solutions |
Note |
|
Authentication failed |
The result parameter in the onJoinChannelResult callback returns AliRtcErrJoinBadToken. |
When an error occurs, the app must check the token for correctness. |
If an API call fails authentication, the system returns an authentication error message in the callback. |
|
Abnormal network connectivity |
The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed. |
When this error occurs, the app must rejoin the meeting. |
The SDK automatically recovers from short network outages. If the outage lasts longer than the preset timeout threshold, the connection times out and disconnects. In this case, the app must check the network status and guide the user to rejoin the meeting. |
|
Abnormal on-premises device |
onLocalDeviceException |
When this abnormal condition occurs, check whether the app has the required permissions and whether the device hardware is working properly. |
The RTC service supports device detection and diagnostics. When an issue occurs with a local device, the RTC service sends a callback to your application. If the SDK cannot resolve the issue on its own, your application must intervene to check if the device is functioning correctly. |
Parameters
|
Parameter |
Type |
Description |
|
listener |
Set the listener for notification events of local user behavior. |
setRtcEngineNotify
Sets a listener to receive callback events for remote users.
public abstract void setRtcEngineNotify(AliRtcEngineNotify listener);This method sets up event callbacks related to remote users, such as notifications when they go online or offline, their audio and video stream ingest status, resolution changes, first frame and first packet transmission and reception for local and remote audio and video, local and remote sound effect and audio accompaniment playback status, mute status, local and remote audio and video stream statistics, SEI reception, custom message reception, and authentication changes. Developers implement these callback methods to handle interactions with remote users.
All callbacks have empty default implementations. You do not need to implement all methods. Implement only those relevant to your business needs.
Avoid performing time-consuming operations in callbacks, such as calling the destroy method. Doing so may cause blocking and affect SDK performance.
When to call
Call this method before joining a channel.
Related callbacks
When exceptions occur, the SDK first attempts internal retries to recover automatically. If recovery fails, the SDK notifies your application through predefined callbacks. Below are key callbacks that require application-level handling:
|
Cause of the abnormality |
Callbacks and Parameters |
Solutions |
Note |
|
Offline |
onBye |
|
The RTC service provides a feature for administrators to remove participants. |
|
Authentication will expire soon |
onWillAuthInfoExpire |
If this exception occurs, the app must re-obtain the latest authentication information. Then, call `refreshAuthInfo` to refresh it. |
Authentication expiration errors occur in two situations: when a user calls an API or during program execution. Therefore, error feedback is provided through an API callback or a separate error callback. |
|
Authentication expired |
onAuthInfoExpired |
When this error occurs, the app must rejoin the meeting. |
Authentication expires in two cases: when a user calls an API or when a program runs. Therefore, the error feedback appears as an API callback or as a separate error callback. |
Parameters
|
Parameter |
Type |
Description |
|
listener |
Set the listener for notification events about remote user behavior to receive messages from the engine. |
getSdkVersion
Retrieves 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 profile.
public abstract int setChannelProfile(AliRTCSdkChannelProfile channelProfile);This method sets the channel profile. Two main profiles are currently supported: video calling and interactive live streaming.
In video calling mode, all users are streamers and can both ingest and pull audio and video streams.
In interactive live streaming 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>. For users who ingest streams in the channel, set their role to streamer (AliRTCSdkInteractive). If a user only needs to pull streams and does not need to ingest streams, set their role to viewer (AliRTCSdkLive). This mode is recommended for RTC scenarios.
We recommend using interactive live streaming mode for all RTC scenarios. Call this method to set the profile to
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 profile while in a channel. You can change it after leaving the channel.
Parameters
|
Parameter |
Type |
Description |
|
channelProfile |
The channel type. For all RTC scenarios, use interactive mode. |
Response description
A value of 0 indicates success. Any other value indicates failure: 1 means the SDK is not initialized or has been destroyed.
setAudioProfile
Sets the audio encoding and scenario modes.
public abstract int setAudioProfile(AliRtcAudioProfile profile, AliRtcAudioScenario scenario);This API sets the audio encoding mode and the audio scenario mode. For more information, see Common audio operations and configurations. The ARTC SDK uses high-quality audio mode (AliRtcEngineHighQualityMode) and music scenario mode (AliRtcSceneMusicMode) by default. If the default settings do not meet your requirements, you need to call this API to change them.
When to call
You can call this method only before joining a channel. You cannot change the settings after joining. You can change them after leaving the channel.
Parameters
|
Parameter |
Type |
Description |
|
profile |
Audio collection or encoding mode parameter. Use high-quality mode (AliRtcEngineHighQualityMode). Note
To interoperate with web, set the sample rate to 48 kHz.
| |
|
scenario |
Audio scenario mode parameters include the following:
Note
For ARTC SDK versions v6.21 and later, do not set to the chat room scenario ( |
Return Description
0: call succeeded. Less than 0: call failed.
isAudioOnly
Checks whether audio-only mode is enabled.
public abstract boolean isAudioOnly();Return Description
A value of true indicates audio-only mode. A value of false indicates audio-video mode.
setAudioOnlyMode
Specifies whether to enable audio-only mode.
public abstract int setAudioOnlyMode(boolean audioOnly);Parameters
|
Parameter |
Type |
Description |
|
audioOnly |
boolean |
Set the audio-only mode or the audio-video mode. Valid values:
|
Response description
A value of 0 indicates success. Any other value indicates failure.
joinChannel[1/3]
Joins a channel using a single-parameter token.
public abstract int joinChannel(String token, String channelId, String userId, String userName);This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[2/3], and joinChannel[3/3] all join a channel. They differ in authentication method and user information passed:
This is a single-parameter joining API. You can join a channel by passing in a token for single-parameter joining that is generated using Token authentication. This API is recommended for joining channels in RTC scenarios.
joinChannel[2/3]is a multi-parameter API for joining a channel. You must pass the multi-parameter channel joining token generated from Token authentication, along with the user information used to generate the token.joinChannel[3/3]is for AI real-time interaction scenarios. Pass a single-parameter token and set the user attributecapabilityProfilebased 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 cancel this 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 method after creating the engine.
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="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. Only then can you join a channel again.This method supports joining only one channel at a time.
Apps using different App IDs cannot interoperate.
Invocation is not required when retrying a failed channel join.
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="712006e223y8z">onJoinChannelResult</a>callback.After you successfully join 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="40a9273affui1">onRemoteUserOnLineNotify</a>callback.
Parameters
|
Parameter |
Type |
Description |
|
token |
String |
The authentication information for joining a meeting with a single parameter. |
|
channelId |
String |
The ID of the channel to join must be the same as the channel ID used to generate the token. |
|
userId |
String |
The user ID for joining the channel must match the value used to generate the token. |
|
userName |
String |
The user's display name. It is not the user ID. |
Return description
A value of 0 indicates success. Any other value indicates failure.
joinChannel[2/3]
Join a channel for a multi-party conference.
public abstract int joinChannel(AliRtcAuthInfo authInfo, String userName);This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[3/3] all join a channel. They differ in authentication method and user information passed:
joinChannel[1/3]is the single-parameter interface for joining a channel. To join a channel, pass a token generated using Token authentication. This interface is recommended for joining a channel in RTC scenarios.This interface is a multi-parameter channel-joining interface. It requires you to provide a multi-parameter channel-joining token generated by Token authentication, and the user information used to generate the token to join the channel.
joinChannel[3/3]is for AI real-time interaction scenarios. Pass a single-parameter token and set the user attributecapabilityProfile.
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 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="474adcf738uxu">setDefaultSubscribeAllRemoteAudioStreams</a>and setDefaultSubscribeAllRemoteVideoStreamsbefore calling this interface to disable subscription to audio streams or video streams.This API is used to join a channel with multiple parameters. Before you call this API, refer to Token authentication to generate the required token.
Limitations
After successfully joining a channel, to join another channel during the session, 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 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="6aefdfedb0op3">onLeaveChannelResult</a>callback fromAliRtcEngineEventListener. Only then can you join a channel again.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 a channel, the remote side 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 is a multi-parameter token. Other parameters related to token generation must match those used during token generation and must not be empty. | |
|
userName |
String |
The user's display name. It is not the user ID. It can be empty. |
Return Description
A value of 0 indicates success. Any other value indicates failure.
joinChannel[3/3]
Joins a channel for AI real-time interaction scenarios.
public abstract int joinChannel(String token, AliRTCSdkChannelParam channelParam);This method joins a channel. ARTC organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[2/3] all join a channel. They differ in authentication method and user information passed:
joinChannel[1/3]is a single-parameter channel-joining interface for RTC scenarios. You can join a channel by passing in a token generated through Token authentication. We recommend using this interface to join a channel in RTC scenarios.joinChannel[2/3]is an interface for multi-participant joining. It requires you to pass in the Token generated through Token authentication for multi-participant joining, and also pass in the user information used to generate the Token to join.This method is for AI real-time interaction scenarios. Pass a single-parameter token and set the user attribute
capabilityProfile. Set it toAliCapabilityProfileAiHumanwhen communicating with AI agents.
By default, when you join a channel, you subscribe to audio and video streams from all other users in the channel and publish your audio and video streams to remote users. 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> before calling this API to disable subscription to audio streams, or call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="0112175788ybe">setDefaultSubscribeAllRemoteVideoStreams</a> to disable subscription to video streams.
Limitations
After successfully joining a channel, to join another channel while in a channel, 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. Only then can you join a channel again.This method supports joining only one channel at a time.
Apps using different App IDs cannot interoperate.
You do not need to invoke the method again to retry a failed channel join.
Related callbacks
After calling this method successfully, the following callbacks are triggered:
The result of the local client joining a channel is reported through the
AliRtcEngineEventListener<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="879ae2fa04zjd">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="9b5662c5a0nvf">onRemoteUserOnLineNotify</a>callback.
Parameters
|
Parameter |
Type |
Description |
|
token |
String |
The token for joining a channel. |
|
channelParam |
Parameters for joining a channel. These are used primarily in AI-powered real-time interaction scenarios and include the following:
|
Return Description
A value of 0 indicates success. Any other value indicates failure.
leaveChannel
Leaves a channel. After calling this method, the SDK terminates real-time communication and leaves the current channel.
public abstract int leaveChannel();This method is an asynchronous operation, and when you call it successfully, the SDK does not immediately leave the channel—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 invoked before the channel is actually left.After leaveChannel completes, destroy the engine and set the engine object to null.
mAliRtcEngine.leaveChannel(); mAliRtcEngine.destroy(); mAliRtcEngine = null;
When to call
Call this method when you need to leave a channel after joining.
If you have joined a channel and need to join another, call this method first.
Related callbacks
Local end: After you call this method, it triggers the
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="80f5e30245vfn">onLeaveChannelResult</a>callback to notify you of the result of leaving the channel.Remote side: After you successfully call this operation, remote users trigger 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
A value of 0 indicates success. Any other value indicates failure.
isInCall
Checks whether you are in a channel.
public abstract boolean isInCall();Return Description
A value of true indicates that you are in a channel. A value of false indicates that you are not in a channel.
setClientRole
Specifies 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 the user role as streamer: The SDK automatically ingests local audio and video streams and pulls audio and video streams from other streamers.
Set the user role as viewer: The SDK does not ingest local audio and video streams but pulls audio and video streams from other streamers.
When to call
You can call this method before or after joining a channel. You can set the role before joining or switch roles after joining.
Limitations
This method works only in interactive mode—that is, when setChannelProfile is set to AliRTCSdkInteractiveLive.
We recommend explicitly setting the user role before joining a channel in interactive mode.
Parameters
|
Parameter |
Type |
Description |
|
clientRole |
User role type. This role applies only in interactive mode. |
getCurrentClientRole
Queries the user role.
public abstract AliRTCSdkClientRole getCurrentClientRole();Return Description
Returns the current user role.
refreshAuthInfo[1/2]
Refreshes the authentication information.
public abstract int refreshAuthInfo(AliRtcAuthInfo authInfo);This method updates authentication information. Tokens expire after a period, preventing the SDK from connecting to the server.
This API and the refreshAuthInfo[2/2] API both update authentication information. However, this API updates tokens for multi-participant meetings, while the refreshAuthInfo[2/2] API updates tokens for single-participant meetings. For information about token generation, see Token Authentication.
When to call
In the following situations:
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 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. At this point, you need to regenerate the Token and then calljoinChannelto rejoin the channel.
Parameters
|
Parameter |
Type |
Description |
|
authInfo |
The authentication information. |
Return Description
A value of 0 indicates success. Any other value indicates failure.
refreshAuthInfo[2/2]
Refreshes the authentication information.
public abstract int refreshAuthInfo(String token);This method updates the token. Tokens expire after a period, preventing the SDK from connecting to the server.
Both this API and the refreshAuthInfo[1/2] operation update authentication information. This API updates the token for joining a meeting with a single parameter, while refreshAuthInfo[1/2] updates the token for joining a meeting with multiple parameters. For more information about token generation, see Token Authentication.
When to call
We recommend regenerating the token on your server and calling this method with the new token in the following cases:
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 reports that the authentication information is about to expire.If you do not update the Token in time, it will trigger
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="3fd674e985gl8">onAuthInfoExpired</a>to notify that authentication has expired. At this point, you need to calljoinChannelto rejoin the channel.
Parameters
|
Parameter |
Type |
Description |
|
token |
String |
The authentication information for single-parameter input. |
Return description
A value of 0 indicates success. Any other value indicates 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 stream. By default, the SDK publishes the audio stream. To disable audio stream publishing, call publishLocalAudioStream(false) before joining the channel.
When to call
You can call this method before or after joining a channel. Calling it before joining modifies the default configuration and takes effect upon joining.
Related callbacks
When the result of local audio stream ingest 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 that the local audio stream ingest status has changed, 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 stream. Valid values:
|
Return Description
A value of 0 indicates success. Any other value indicates failure.
isLocalAudioStreamPublished
Queries whether an audio stream is published.
public abstract boolean isLocalAudioStreamPublished();Return Instructions
A value of true indicates that the audio stream is published. A value of false indicates that the audio stream is not published.
setDefaultSubscribeAllRemoteAudioStreams
Specifies whether to subscribe to audio streams of remote users by default.
public abstract int setDefaultSubscribeAllRemoteAudioStreams(boolean sub);This method configures whether the system subscribes to remote users' audio streams by default. This setting affects the audio stream subscription behavior of new users joining the channel. Unless you have specific requirements, we recommend setting this to true.
When to call
You can call this method before or after joining a channel.
Before joining:
By default, the SDK subscribes to remote users' audio streams when joining a channel. To change this behavior, call this method before joining.
After joining:
To stop default subscription, call
setDefaultSubscribeAllRemoteAudioStreams(false). Then, newly joined users' audio streams are not subscribed to.After you stop the default subscription, you can call the subscribeRemoteAudioStream API to resume subscription to the audio stream of a specified user, and call it multiple times to resume subscription for multiple users.
After stopping default subscription, calling
setDefaultSubscribeAllRemoteAudioStreams(true)resumes subscription only for users who join after the call. It does not resume subscription for remote users who joined during the stopped period.
Parameters
|
Parameter |
Type |
Description |
|
sub |
boolean |
Whether to accept audio streams by default. Valid values are:
|
Return description
A value of 0 indicates success. Any other value indicates failure.
subscribeRemoteAudioStream
Stops or resumes pulling the audio stream of a specific remote user.
public abstract int subscribeRemoteAudioStream(String uid, boolean sub);This method stops or resumes subscribing to the audio stream of a specific remote user. Unless you have specific requirements, we recommend setting this to true.
The SDK subscribes by default to audio streams from all remote users when joining 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 a meeting to disable this default configuration.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
sub |
boolean |
Specifies whether to pause or resume the subscription to the audio stream of a specific remote user.
|
Return description
A value of 0 indicates success. Any other value indicates failure.
subscribeAllRemoteAudioStreams
Specifies whether to receive audio streams of all remote users.
public abstract int subscribeAllRemoteAudioStreams(boolean sub);This method is the master switch for subscribing to remote audio streams. We recommend setting it to true. If set to false, it causes:
All remote audio streams in the current session stop being subscribed to.
New users who join later are also not subscribed to.
You cannot use
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e09342eeb0z4k" id="a56b5f2a3f56k">subscribeRemoteAudioStream</a>to individually control the audio stream of a specified user.
To resume subscription, call this method again and set it to true.
The SDK subscribes by default to audio streams from all remote users when you join a meeting. To modify this behavior, you can 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 joining a meeting to disable this default configuration.
Parameters
|
Parameter |
Type |
Description |
|
sub |
boolean |
Specifies whether to receive all remote audio streams. Valid values:
|
Return description
A value of 0 indicates success. Any other value indicates failure.
publishLocalVideoStream
Specifies whether to publish the camera stream.
public abstract int publishLocalVideoStream(boolean enable);This method controls whether to publish the locally captured video stream.
The SDK publishes the video stream by default. To disable video stream publishing, call publishLocalVideoStream(false) before joining the channel.
When to call
You can call this method before or after joining a channel.
Calling it before joining modifies the default configuration and takes effect upon joining.
Related callbacks
When the status of local audio stream ingest changes, the local end 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 the latest status of the audio stream ingest, and the remote end 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 that the remote user's audio and video streams have changed.
Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean | Specifies whether to publish the video track. Valid values:
|
Return Description
A value of 0 indicates success. Any other value indicates failure.
isLocalVideoStreamPublished
Queries whether a camera stream is published.
public abstract boolean isLocalVideoStreamPublished();Return Description
A value of true indicates that the camera stream is published. A value of false indicates that the camera stream is not published.
setDefaultSubscribeAllRemoteVideoStreams
Specifies whether to subscribe to video streams of remote users by default.
public abstract int setDefaultSubscribeAllRemoteVideoStreams(boolean sub);This method specifies whether to subscribe to video streams of remote users by default. The SDK subscribes by default.
When to call
You can call this method before or after joining a channel. If you call setDefaultSubscribeAllRemoteVideoStreams(false) after joining, you will not receive video streams from users who join afterward.
After you stop receiving video streams, call subscribeRemoteVideoStream and specify the ID of the remote user to resume receiving their video stream. To resume receiving video streams from multiple users, you need to call subscribeRemoteVideoStream multiple times. setDefaultSubscribeAllRemoteVideoStreams(true) only resumes receiving video streams from users who join the channel later.
This method specifies whether to subscribe to video streams of remote users by default.
By default, the SDK subscribes to remote users' audio and video streams when joining a channel. To change this behavior, call this method before joining.
Parameters
|
Parameter |
Type |
Description |
|
sub |
boolean |
Specifies whether to subscribe to the video tracks of remote users. Valid values:
|
Return Description
A value of 0 indicates success. Any other value indicates failure.
subscribeRemoteVideoStream
Stops or resumes subscribing to a specified remote video stream.
public abstract int subscribeRemoteVideoStream(String uid, AliRtcVideoTrack track, boolean sub);Subscribes to or unsubscribes from a specified user's video stream.
By default, the SDK subscribes to the video streams of all remote users when you join a meeting. To change 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 cancel this default configuration.
When to call
You can call this method before or after joining a channel.
Parameters
|
Parameter |
Type | Description |
|
uid |
String |
User ID |
|
track |
Video stream type. | |
|
sub |
boolean |
Specifies whether to receive the video stream from a specified user.
|
Return description
0: the method executed successfully.
Non-zero: the method failed.
subscribeAllRemoteVideoStreams
Stops or resumes receiving all remote video streams.
public abstract int subscribeAllRemoteVideoStreams(boolean sub);This method is the master switch for subscribing to remote video streams. If set to false, it causes:
All remote video streams in the current session stop being subscribed to.
New users who join later will not subscribe (even if you have set
setDefaultSubscribeAllRemoteVideoStreams(true) to enable default subscription).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 it to true.
By default, the SDK subscribes to all remote users' video streams when joining a channel. To change this behavior, call setDefaultSubscribeAllRemoteVideosStreams(false) before joining.
Parameters
|
Parameter |
Type |
Description |
|
sub |
boolean |
Specifies whether to subscribe to the video tracks of all remote users. Valid values:
|
Return Description
A value of 0 indicates success. Any other value indicates failure.
subscribeRemoteMediaStream[1/2]
Stops or resumes the media stream of 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 and is ignored.
Related methods
Compared to <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 API utilizes two Boolean parameters, subVideo and subAudio, to specify whether to subscribe to the remote audio and video streams. The videoTrack parameter controls which video stream to pull.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
videoTrack |
The type of the video stream. | |
|
subVideo |
boolean |
Specifies whether to subscribe to the video stream of the remote user. Valid values:
|
|
subAudio |
boolean |
Stop or resume pulling the audio stream of a specific remote user. Valid values:
|
Return description
A value of 0 indicates that the call is successful. Any other value indicates that the call failed.
subscribeRemoteMediaStream[2/2]
Stops or resumes subscribing to a remote user's audio and video streams in a single call.
public abstract int subscribeRemoteMediaStream(String uid, AliRtcVideoTrack videoTrack, AliRtcAudioTrack audioTrack) ;This interface merges subscribed remote audio and video streams.
Related methods
Unlike subscribeRemoteMediaStream[1/2], this method uses the videoTrack and audioTrack parameters to specify the desired subscription state in a single API call. For example:
If you want to subscribe to the camera stream and the microphone stream, set videoTrack and audioTrack to
AliRtcVideoTrackCameraandAliRtcAudioTrackMic, respectively, when you invoke.To unsubscribe from the camera stream but continue subscribing to the microphone stream, set the
videoTrackparameter toAliRtcVideoTrackNoand theaudioTrackparameter toAliRtcAudioTrackMic.To unsubscribe from both, you can set videoTrack and audioTrack to
AliRtcVideoTrackNoandAliRtcAudioTrackNo, respectively.To subscribe to both the camera and screen-sharing streams, set the videoTrack parameter to
AliRtcVideoTrackBoth. The same logic applies to audio streams.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The user ID is a unique identifier that the App server assigns. |
|
videoTrack | The type of video stream. | |
|
audioTrack |
The type of the audio stream. |
Return Description
0: Success.
<0: Failure.
subscribeRemoteDestChannelStream
Subscribe 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 ID of the remote channel. |
|
uid |
String |
The ID of the remote user. |
|
track |
The video stream to subscribe to. | |
|
sub_audio |
boolean |
Controls whether to stop or resume pulling the audio stream of a specific remote user. Valid values:
|
|
sub |
boolean |
Stops or resumes subscribing to the stream of a specified user across channels. |
Return Description
A return value of 0 indicates that the method call succeeded, while any other value indicates that the call failed.
subscribeRemoteDestChannelAllStream
Stops or resumes 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 ID of the remote target channel. |
|
videoTrack |
The type of video stream to subscribe to. | |
|
sub_audio |
boolean |
Whether to subscribe to the audio stream of a remote user.
|
|
sub |
boolean |
Stop or resume cross-channel subscriptions for a specified user stream.
|
Return description
0: The method call succeeded.
Non-zero: The method call failed.
setRemoteAudioVolume
Adjusts the playback volume of the pulled audio stream.
public abstract int setRemoteAudioVolume(String uid, int volume);You can use this method to adjust the playback volume of a specified user's audio stream on the local device.
This setting affects only the listening experience on the local device.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
User ID. A unique identity for the user, usually assigned by the app server. |
|
volume |
int |
Playback volume, with a value range of [0, 100].
|
Return Description
0: The method call succeeded.
Non-zero: The method call failed, for example, due to an invalid volume value.
muteLocalMic
Stops or resumes sending local audio data.
public abstract int muteLocalMic(boolean mute, AliRtcMuteLocalAudioMode mode);Muting sends silent frames. Audio capture and encoding continue to run.
When to call
You can call this method before or after joining a channel.
Related callbacks
After the call succeeds, the remote user triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ea457055e4izi" id="cce3d390a3xud">onUserAudioMuted</a> notification to indicate whether they are muted.
Parameters
|
Parameter |
Type |
Description |
|
mute |
boolean |
Stops or resumes sending local audio data. Valid values:
|
|
mode |
The mute mode. By default, the microphone is muted. |
Return Description
A return value of 0 indicates success. Any other value indicates failure. Muting sends silent frames, but audio capture and encoding continue to run.
muteRemoteAudioPlaying
Stops or resumes playback of the remote audio stream.
public abstract int muteRemoteAudioPlaying(String uid, boolean mute);This API controls playback of a specified remote user’s audio stream only. It does not affect stream pulling or decoding of the remote audio. To unsubscribe from a user’s audio stream, 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 set this before or after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
mute |
boolean |
Stops or resumes remote audio playback. Valid values:
|
Return Description
A return value of 0 indicates success. Any other value indicates failure.
muteAllRemoteAudioPlaying
Stops or resumes playing all remote audio streams.
public abstract int muteAllRemoteAudioPlaying(boolean mute);This method stops or resumes all remote audio streams.
This method only stops playback. Stream pulling and decoding are not affected.
When to call
You can set this before or after you join a channel.
Parameters
|
Parameter |
Type |
Description |
|
mute |
boolean |
Stops or resumes playback of all remote audio. The valid values are:
|
Return description
A value of 0 indicates that the call is successful. Any other value indicates failure.
startAudioCapture[1/2]
Starts audio capture.
public abstract int startAudioCapture();This method starts audio capture. You can call this method before joining a channel to enable audio capture in advance. If this method is not called, the SDK automatically controls the audio capture device. You can also call this method to re-enable audio capture after calling stopAudioCapture.
When to call
You can call this method 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> API uses parameters to control whether the audio capture device remains enabled after you leave a meeting.
Related callbacks
After you call this method, the onLocalAudioStateChanged callback notifies you of the change in the local audio capture status.
Return Description
A value of 0 indicates that the call is successful. Any other value indicates that the call has failed.
startAudioCapture[2/2]
Starts audio capture.
public abstract int startAudioCapture(boolean keepAlive);Disables microphone capture after muting.
This method starts audio capture. You can call it before joining a channel to enable audio capture in advance. If you do not set this method, the SDK automatically controls the audio capture device.
When to call
You can call this method before or after joining a channel.
Related methods
Compared to startAudioCapture[1/2], this method lets you control whether the capture device remains active after leaving a channel using the keepAlive parameter.
Related callbacks
After calling this method to change the local audio capture status, you can retrieve status changes through the onLocalAudioStateChanged callback.
Parameters
|
Parameter |
Type |
Description |
|
keepAlive |
boolean |
The status of the audio collection device after you leave a channel. Valid values:
|
Return Description
A return value of 0 indicates success. Any other value indicates failure.
stopAudioCapture
Stops audio capture.
public abstract int stopAudioCapture();The SDK enables audio capture by default. When you start a preview or join a channel, audio capture starts automatically. Call this method to stop audio device capture.
Related callbacks
After you call this method, the SDK triggers the onLocalAudioStateChanged callback to report the change in the local audio capture status.
Return Description
A return value of 0 indicates that the call was successful. Any other value indicates that the call failed.
setDefaultAudioRoutetoSpeakerphone
Sets whether the default audio output device is the speakerphone.
public abstract int setDefaultAudioRoutetoSpeakerphone(boolean defaultToSpeakerphone);This method configures the default audio routing device before you join a channel. You can set the default output to either the earpiece or the speakerphone. By default, the SDK uses the speakerphone. To change this default, call this method before joining a channel.
The SDK defines an audio routing priority that automatically switches based on the current peripheral connection status, as follows: wired headset > Bluetooth headset > user settings > default settings. Therefore, if no peripheral is connected and enableSpeakerphone is not set, the SDK applies the default settings.
For more information about audio routing settings, see audio routing settings.
Mobile devices typically support two audio output devices: the earpiece and the speakerphone:
When audio is routed to the earpiece, the sound is quieter and requires holding the phone close to your ear, providing better privacy and making it suitable for phone calls.
When audio is routed to the speakerphone, the sound is louder and enables hands-free use without holding the phone to your ear.
Related methods
This method modifies the default audio routing configuration. The enableSpeakerphone method sets the current audio routing device.
When to call
You can call this method before or after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
defaultToSpeakerphone |
boolean |
Use speaker by default?
|
Response description
0: the method call succeeded.
<0: the method call failed.
enableSpeakerphone
Sets the audio output device to either the headset or the speaker.
public abstract int enableSpeakerphone(boolean enable);This method selects the current audio playback device after joining a channel, switching between the earpiece and the speaker. If you do not call this method, playback uses the device specified by the default audio route.
The SDK defines a predefined priority order for audio routing and performs automatic switchover based on the current peripheral connection status. The priority order is as follows: wired headset > Bluetooth headset > user settings > default settings. Therefore, when a peripheral is connected, this API call has no effect. For more information about audio routing settings, see Audio Routing Settings.
When to call
You can call this method 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 the default audio routing settings and sets the current routing device.
Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean |
Specifies whether audio output uses the earpiece or speaker. Valid values:
|
Return description
A value of 0 indicates that the call succeeded. Any other value indicates failure.
isSpeakerOn
Determines whether the current audio output device is the earpiece or the speaker.
public abstract boolean isSpeakerOn();Return Description
A value of true indicates the speaker. A value of false indicates the earpiece.
enableAudioVolumeIndication
Enable the user volume prompt.
public abstract int enableAudioVolumeIndication(int interval, int smooth, int reportVad);This method enables the SDK to periodically report the volume of the local user and the remote user with the highest current volume. To use this feature, implement the AliRtcAudioVolumeObserver class and call registerAudioVolumeObserver to register the observer.
When to call
You can call this method before or after you join a channel.
Related callbacks
After you successfully call this method, if users are publishing streams in the channel, the SDK triggers the following two callbacks at a specified interval:
The AliRtcAudioVolumeObserver#onAudioVolume callback reports the audio volume of each speaker. The frequency of this callback is determined by the interval parameter.
Voice activity detection: When an active speaker is detected, their user ID (UID) is reported through the AliRtcAudioVolumeObserver#onActiveSpeaker callback.
Parameters
|
Parameter |
Type |
Description |
|
interval |
int |
Time interval.
|
|
smooth |
int |
The smoothing coefficient. A higher value increases the degree of smoothing. A lower value reduces smoothing but improves real-time performance.
|
|
reportVad |
int |
The switch for local audio detection.
|
Return Description
A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.
enableEarBack
Enables in-ear monitoring.
public abstract int enableEarBack(boolean enable);This method enables or disables in-ear monitoring. You can obtain better results by enabling in-ear monitoring when wearing wired or Bluetooth headphones.
When to call
You can call this method before or after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean |
Specifies whether to enable in-ear monitoring. Valid values:
|
Return description
A value of 0 indicates success. Any other value indicates failure.
setEarBackVolume
Sets the in-ear monitoring volume.
public abstract int setEarBackVolume(int volume) ;This method takes effect only after in-ear monitoring is enabled by calling enableEarBack.
When to call
You can call this method before or after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
Volume |
int |
Volume. Valid values: 0 to 100. Default value: 100.
|
Return Instructions
0: The method call was successful.
<0: The method call failed.
startAudioPlayer
Starts the audio playback device.
public abstract int startAudioPlayer();You can use this method to enable audio playback in advance. If you do not call this method, the SDK automatically enables audio playback after you subscribe to an audio stream.
Return Description
0: The call succeeded.
A non-zero value: The call failed and returns an error code.
stopAudioPlayer
Stops the audio playback device.
public abstract int stopAudioPlayer();This interface stops audio playback and is the counterpart to startAudioPlayer.
Return Information
0: The call succeeded.
Non-zero: The call failed. An error code is returned.
setPlayoutVolume
You can set the local playback volume.
public abstract int setPlayoutVolume(int volume);Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
Recording volume. Value range: [0, 400].
|
Response description
0: The call succeeded.
A non-zero value: The call failed.
setRecordingVolume
You can set the recording volume.
public abstract int setRecordingVolume(int volume);Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
The recording volume. The value range is [0, 400].
|
Return Description
0: the method call succeeded.
A non-zero return code indicates that the call failed.
playAudioFileTest
You can play the audio file.
public abstract int playAudioFileTest(String filePath) ;You can use this method to play an audio file before joining a channel to test audio playback.
When to call
You can call this method only before joining a channel.
Call Limits
Multiple calls overwrite previous ones. Calling this method stops any currently playing file.
Parameters
|
Parameter |
Type |
Description |
|
filePath |
filePath |
The file path. |
Return description
0: the method call succeeded.
A non-zero value indicates that the call failed.
stopAudioFileTest
Stop the playback of the audio file.
public abstract int stopAudioFileTest();This interface corresponds to the playAudioFileTest interface and stops audio file playback.
Limitations
You can call this method only before you join a channel.
Return description
0: call succeeded.
Non-zero: call failed.
startAudioCaptureTest
Starts an audio capture device test before a call.
public abstract int startAudioCaptureTest();You can call this method to test whether the local audio capture device is working correctly before a call. After you call this method, the SDK reports the volume of the audio capture device through the AliRtcAudioVolumeObserver::OnTestAudioVolume callback.
When to call
You must call this method before joining a channel. After the test is complete, call stopAudioCaptureTest to stop the test and release the audio device.
Return Description
0: The call is successful.
Non-zero: The call failed. An error code is returned.
stopAudioCaptureTest
Disable audio capture detection.
public abstract int stopAudioCaptureTest();This method stops the audio capture device test. After you call startAudioCaptureTest, you must call this method to stop the test.
When to call
You can call this method before joining a channel.
Return Description
0: The call succeeded.
A non-zero value: The call failed, and an error code is returned.
setAudioEffectVoiceChangerMode
Sets the voice change mode.
public abstract int setAudioEffectVoiceChangerMode(AliRtcAudioEffectVoiceChangerMode mode);Parameters
|
Parameter |
Type |
Description |
|
mode |
The voice changer mode. The default value is AliRtcSdk_AudioEffect_Voice_Changer_OFF (off). |
Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure.
setAudioEffectPitchValue
You can set pitch adjustment parameters.
public abstract int setAudioEffectPitchValue(double value);Parameters
|
Parameter |
Type |
Description |
|
value |
double |
Valid values: 0.5 to 2.0. The default value is 1.0, which indicates that the pitch remains the same. |
Return description
A value of 0 indicates that the method call succeeded. Any other value indicates that it failed.
setAudioEffectReverbMode
Sets the reverberation mode.
public abstract int setAudioEffectReverbMode(AliRtcAudioEffectReverbMode mode);Parameters
|
Parameter |
Type |
Description |
|
mode |
The reverberation mode. The default value is AliRtcAudioEffectReverb_Off, which indicates no reverberation. |
Return description
A return value of 0 indicates that the method call was successful. Any other value indicates that the method call failed.
setAudioEffectReverbParamType
You can set the type and parameters for the reverberation sound effect.
public abstract int setAudioEffectReverbParamType(AliRtcAudioEffectReverbParamType type, float value);Parameters
|
Parameter |
Type |
Description |
|
type |
The sound effect reverberation parameter. | |
|
value |
float |
The parameter value. |
Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure.
setAudioEffectBeautifyMode
Sets a predefined voice beautification mode.
public abstract int setAudioEffectBeautifyMode(AliRtcAudioEffectBeautifyMode mode);This method sets a predefined voice beautification mode provided by the SDK. It is suitable for scenarios that require enhanced vocal quality, such as voice live streaming, karaoke, and voice social networking. By selecting a voice beautification mode, you can alter the sound of the human voice, such as making it more resonant or improving its clarity. This enhances the listening experience for remote users.
When to call
You can call this method before or after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
Mode |
Vocal sound effect mode. See the enumeration definition. |
Return value
0: The operation was successful.
A non-zero value: The operation failed.
setAudioEffectEqualizationParam
Sets the audio equalizer (EQ) parameters to adjust the gain of a specified frequency band.
public abstract int setAudioEffectEqualizationParam(AliRtcAudioEffectEqualizationBandFrequency bandIndex, float gain);This method adjusts the graphic equalizer for locally captured voice and audio signals. By adjusting the gain (in dB) of a specific frequency band, you can customize the sound for purposes such as optimizing voice clarity, highlighting vocals, and improving noise reduction.
The equalizer supports the full audio spectrum from 31 Hz to 16 kHz across 10 standard bands. The gain for each band can be set independently to a value from -15 dB to 15 dB. The default value is 0 dB, which indicates no enhancement or attenuation.
Limitations
You must enable the voice beautification mode by calling
setAudioEffectBeautifyModebefore you call this method.
Parameters
|
Parameter |
Type |
Description |
|
bandIndex |
The band index to adjust, corresponding to a segment within the center frequency range (31 Hz to 16 kHz). | |
|
gain |
float |
Gain value, in dB. Valid values range from -15 to 15. |
Return Description
0: The method call succeeded.
A non-zero value: The method call failed.
addExternalAudioStream
You can add an external audio stream.
public abstract int addExternalAudioStream(AliRtcExternalAudioStreamConfig config);This method adds an external audio stream. Follow these steps:
You can 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 its ID.You can call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#930f22d3dcdco" id="d3deb62b2fl0f">pushExternalAudioStreamRawData</a>to push audio data into the external audio stream.When ending a call, you must 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.
If you want to publish custom audio capture in a channel, see Custom Audio Capture.
When to call
|
Parameter |
Type |
Description |
|
config |
AliRtcExternalAudioStreamConfig |
External audio stream configuration. |
Return description
A return value greater than 0 indicates a successful method call and represents the ID of the external audio stream. Any other value indicates that the method call failed.
pushExternalAudioStreamRawData
You can input external audio stream data.
public abstract int pushExternalAudioStreamRawData(int streamId, AliRtcAudioFrame rawData);Use this interface to send data to a specified audio stream. The steps are as follows:
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 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="880fe8cd02j10">pushExternalAudioStreamRawData</a>to push audio data to the created audio stream.After the call ends, invoke
<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 about publishing audio from a custom source in a channel, see Custom Audio Capture.
When to call
Call this method after joining a channel.
Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
The ID of the external audio stream. |
|
rawData |
AliRtcAudioFrame |
Audio data |
Return Description
A return value of 0 indicates that the method call was successful. Any other value indicates that the method call failed.
setExternalAudioStreamPublishVolume
Sets the publishing volume of an external audio stream.
public abstract int setExternalAudioStreamPublishVolume(int streamId, int publishVolume);Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
The ID of the external audio stream. |
|
publishVolume |
int |
The volume of the external audio for stream ingest. Valid values: 0 to 100. |
Return description
A return value of 0 indicates that the call was successful. Any other value indicates that the call failed.
getExternalAudioStreamPublishVolume
Retrieve the stream ingest volume of the external audio stream
public abstract int getExternalAudioStreamPublishVolume(int streamId);Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
The ID of the external audio stream. |
Return Description
Stream ingest volume: The valid values are 0 to 100. A value less than 0 indicates a failure.
setExternalAudioStreamPlayoutVolume
Sets the playback volume of an external audio stream.
public abstract int setExternalAudioStreamPlayoutVolume(int streamId, int playoutVolume);Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
The ID of the external audio stream. |
|
playoutVolume |
int |
The playback volume. Valid values: 0 to 100. |
Return description
A value of 0 indicates that the call is successful. Any other value indicates that the call failed.
getExternalAudioStreamPlayoutVolume
Retrieve the playback volume of the external audio stream
public abstract int getExternalAudioStreamPlayoutVolume(int streamId);Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
The ID of the external audio stream. |
Response description
The playback volume has valid values ranging from 0 to 100. A value less than 0 indicates failure.
removeExternalAudioStream
Removes an external audio stream.
public abstract int removeExternalAudioStream(int streamId);This method removes the external audio stream that corresponds to the specified stream ID. It is the counterpart to the addExternalAudioStream method.
When to call
To use the custom audio input feature, you must first call the addExternalAudioStream method to add an audio stream and obtain its stream ID. Then, call the pushExternalAudioStreamRawData method to push your audio data to the SDK. When you want to stop using custom audio input, call this method to remove the audio stream and release its resources.
Parameters
|
Parameter |
Type |
Description |
|
streamId |
int |
External audio stream ID, the return value from a successful call to the `addExternalAudioStream` method. |
Return Description
0: The call is successful.
<0: The call failed. An error code is returned.
getAudioFileInfo
Retrieves audio file information.
public abstract int getAudioFileInfo(String fileName);You can call this interface asynchronously to retrieve the duration of a file. This is an asynchronous interface, and you can obtain audio file information using onAudioFileInfo.
Parameters
|
Parameter |
Type |
Description |
|
fileName |
String |
Path to the audio file. |
Back to Introduction
0: The call succeeded.
Non-zero: An error code is returned.
startAudioAccompany
Starts audio accompaniment mixing.
public abstract int startAudioAccompany(String fileName, AliRtcAudioAccompanyConfig config) ;This interface plays local or online accompaniment files. It is an asynchronous interface. After you call this interface, 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 overwrite the previous accompaniment playback.
Parameters
|
Parameter |
Type |
Description |
|
fileName |
String |
The path to the accompaniment file. |
|
config |
Accompaniment playback configuration includes options for local playback only, microphone replacement, loop count, playback start position, volume, and other settings. |
Return Description
0: The call succeeded.
Non-zero: The call failed and returns an error code.
stopAudioAccompany
Sets the headset or speaker as the audio output device.
public abstract int stopAudioAccompany() ;This interface is the counterpart to startAudioAccompany and stops the playback of the audio accompaniment.
When to call
You can call this method before or after joining a channel.
Response description
0: The call succeeded.
Non-zero: The call failed and returns an error code.
setAudioAccompanyVolume
Sets the volume of the audio accompaniment for both local playback and stream ingest.
public abstract int setAudioAccompanyVolume( int volume) ;This API sets the audio accompaniment volume for local playback and for publishing. To set only the local playback volume, use setAudioAccompanyPlayoutVolume. To set only the publish volume, use setAudioAccompanyPublishVolume.
Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
Accompaniment volume. Valid values: [0, 100]. 0: Muted. 100: Original file volume. |
Response description
0: The call succeeded.
A non-zero value: The call failed and returns an error code.
setAudioAccompanyPublishVolume
Sets the volume of the audio accompaniment for stream ingest.
public abstract int setAudioAccompanyPublishVolume(int volume) ;Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
Accompaniment volume. Range: [0, 100]. 0: Mute. 100: Original file volume. |
Return description
0: The call succeeded.
A non-zero value: The call failed. The returned value is an error code.
getAudioAccompanyPublishVolume
Retrieves the ingest volume for the accompaniment stream.
public abstract int getAudioAccompanyPublishVolume() ;Response description
The ingest volume for the accompaniment music stream.
0 to 100: success.
Other values: error code.
setAudioAccompanyPlayoutVolume
Sets the local playback volume of the accompaniment.
public abstract int setAudioAccompanyPlayoutVolume(int volume) ;Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
Accompaniment volume. Valid values: [0, 100]. 0: Mute. 100: Original file volume. |
Return Description
0: The call succeeded.
A non-zero value: The call failed and an error code is returned.
getAudioAccompanyPlayoutVolume
Queries the local playback volume of the accompaniment.
public abstract int getAudioAccompanyPlayoutVolume() ;Return Description
The local playback volume of the accompaniment.
[0-100]: Success.
Other values: Error code.
pauseAudioAccompany
Pause the accompaniment mixing.
public abstract int pauseAudioAccompany();Return Description
0: The call succeeded.
Non-zero: The call failed and returned an error code.
resumeAudioAccompany
You can restart the accompaniment mixing.
public abstract int resumeAudioAccompany();Return description
A value of 0 indicates that the call succeeded.
A non-zero value indicates that the call failed and returns an error code.
getAudioAccompanyDuration
Retrieves the duration of the accompaniment file, in milliseconds.
public abstract int getAudioAccompanyDuration();This method retrieves the duration of the current accompaniment file.
Return description
>= 0: duration of the accompaniment file.
< 0: the call failed and returns an error code.
getAudioAccompanyCurrentPosition
Obtains the playback progress of the accompaniment file, in milliseconds.
public abstract int getAudioAccompanyCurrentPosition();This method obtains the playback progress of the current accompaniment file, in milliseconds.
Response description
A value greater than or equal to 0: The playback progress of the accompaniment file.
A value less than 0: The call failed. An error code is returned.
setAudioAccompanyPosition
Sets the playback position of the accompaniment.
public abstract int setAudioAccompanyPosition(int posMs);This method sets the playback progress of the accompaniment. It is useful for features such as dragging a progress bar. After this method is successfully called, the accompaniment plays from the specified position.
Parameters
|
Parameter |
Type |
Description |
|
posMs |
int |
Progress bar position, in milliseconds. |
Return Description
0: The call succeeded.
A non-zero value: The call failed. 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 user-assigned ID for the sound effect file. |
|
filePath |
String |
The path of the sound effect. |
Return description
A value of 0 indicates that the call succeeded. Any other value indicates failure.
unloadAudioEffect
Deletes a preloaded sound effect file.
public abstract int unloadAudioEffect(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The user-assigned ID for the sound effect file. |
Return description
A value of 0 indicates that the call is successful. Any other value indicates failure.
playAudioEffect
Starts playing 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 file. |
|
filePath |
String |
The path of the sound effect. |
|
cycles |
int |
Number of loops. A value of -1 specifies infinite loops. |
|
publish |
boolean |
Specifies whether to push the sound effect audio stream to the remote end. Valid values:
|
Return description
A value of 0 indicates that the call is successful. A non-zero value indicates that the call failed.
stopAudioEffect
Stops playing a sound effect.
public abstract int stopAudioEffect(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The user-assigned ID for the sound effect file. |
Return description
A return value of 0 indicates that the call was successful. A non-zero value indicates that the call failed.
stopAllAudioEffects
Stops playing all sound effects.
public abstract int stopAllAudioEffects();Return Description
A value of 0 indicates that the call was successful. A non-zero value indicates that the call failed.
setAudioEffectPublishVolume
Sets the volume for the sound effect stream ingest.
public abstract int setAudioEffectPublishVolume(int soundId, int volume);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID that the user assigns to the sound effect file. |
|
volume |
int |
The volume of the mixed audio. Valid values: 0 to 100. Default value: 50. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
getAudioEffectPublishVolume
Queries the sound effect stream ingest volume.
public abstract int getAudioEffectPublishVolume(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID assigned to the sound effect file. |
Response description
A value of 0 indicates that the call is successful. Any other value indicates failure.
setAudioEffectPlayoutVolume
Sets the local playback volume of the sound effect.
public abstract int setAudioEffectPlayoutVolume(int soundId, int volume);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID that the user assigns to the sound effect file. |
|
volume |
int |
The volume of the mixed audio. Valid values: 0 to 100. Default value: 50. |
Return description
A return value of 0 indicates that the call is successful. Any other value indicates failure.
getAudioEffectPlayoutVolume
Retrieves the local playback volume for the sound effect on Android and iOS devices.
public abstract int getAudioEffectPlayoutVolume(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID the user assigns to the sound effect file. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
setAllAudioEffectsPublishVolume
Sets the mixing volume for all sound effects in the stream ingest.
public abstract int setAllAudioEffectsPublishVolume(int volume);Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
The volume of the mixed audio. Valid values: 0 to 100. Default value: 50. |
Return description
A return value of 0 indicates success. Any other value indicates failure.
setAllAudioEffectsPlayoutVolume
Sets the local playback volume for all sound effects (Android and iOS).
public abstract int setAllAudioEffectsPlayoutVolume(int volume);Parameters
|
Parameter |
Type |
Description |
|
volume |
int |
The volume of the mixed audio. Valid values: 0 to 100. Default value: 50. |
Return description
A value of 0 indicates that the call is successful. 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 |
Recording type. | |
|
recordFormat |
Format type (wav, aac, mp4). | |
|
filePath |
String |
Recording file name. |
|
audioConfig |
Audio configuration. | |
|
videoConfig |
Video configuration. | |
|
maxSize |
long |
Maximum file size. |
|
maxDuration |
long |
Maximum file duration. |
Return value
A return value of TRUE indicates success. Any other value indicates failure.
Call this method after the stream is successfully published (
onVideoPublishStateChanged) to record the locally encoded video stream to a local file.When recording an audio stream, this method records a file that contains a mix of local and remote audio.
stopRecord
Stops recording media files.
public abstract void stopRecord();Parameters
None.
pauseAudioEffect
Pauses a sound effect.
public abstract int pauseAudioEffect(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID that the user assigns to the sound effect file. |
Return Description
A return value of 0 indicates success. Any other value indicates failure.
pauseAllAudioEffects
Pauses all sound effects.
public abstract int pauseAllAudioEffects();Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure.
resumeAudioEffect
Resumes playback of a sound effect.
public abstract int resumeAudioEffect(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID that the user assigns to the sound effect file. |
Return description
A value of 0 indicates that the call succeeded. Any other value indicates failure.
resumeAllAudioEffects
You can resume playing all sound effects.
public abstract int resumeAllAudioEffects();Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure.
createRenderSurfaceView
Creates a SurfaceView rendering view.
public abstract SophonSurfaceView createRenderSurfaceView(Context context);You must call this method to display video views instead of creating a SurfaceView directly. To use this method:
Assign the return value to AliRtcVideoCanvas#view.
Call setLocalViewConfig to set the local preview view or setRemoteViewConfig to set the remote preview view.
When to call
You can call this method before or after you join a channel.
Limitations
You must call this method on 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 local video stream to a view and configuring the local user's view rendering mode, mirroring mode, and rotation angle. It affects only the local user's preview and not the ingested video. To set the remote user interface view, call setRemoteViewConfig.
If the view parameter in AliRtcVideoCanvas is empty, rendering stops.
To change the renderMode parameter of AliRtcVideoCanvas during playback, keep all other parameters unchanged and modify only renderMode.
To update the mirrorMode parameter of AliRtcVideoCanvas during playback, keep all other parameters unchanged and modify only mirrorMode.
You can 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 |
Rendering parameters, including the rendering window and rendering mode. | |
|
track |
Video stream type. |
Return Instructions
A value of 0 indicates success. Any other value indicates failure.
setRemoteViewConfig
You can set the rendering window and drawing parameters for the remote video.
public abstract int setRemoteViewConfig(AliVideoCanvas canvas, String uid,AliRtcVideoTrack track);This method binds the display view for a specified remote user’s video stream and configures the rendering mode, mirroring mode, and rotation angle for that user’s video when displayed locally. It affects only the video shown to the local user. To configure the local preview view, call setLocalViewConfig.
If the view parameter of AliRtcVideoCanvas is empty, rendering stops.
To reset the renderMode parameter of AliRtcVideoCanvas during playback, modify the value of renderMode while keeping all other parameters unchanged.
To change the `mirrorMode` parameter of AliRtcVideoCanvas during playback, modify the `mirrorMode` value while keeping the other parameters unchanged.
When to call
We recommend that you call this function when you receive the onRemoteTrackAvailableNotify callback. You can set it when a remote user’s video becomes available.
Parameters
|
Parameter |
Type |
Description |
|
canvas |
The rendering configuration, including the rendering window and rendering mode. | |
|
uid |
String |
User ID. |
|
track |
The type of video stream to set. |
Return Description
A value of 0 indicates that the call is successful, while any other value indicates failure.
setCameraCapturerConfiguration
Sets the camera capture preferences, such as the camera direction and capture frame rate.
public abstract int setCameraCapturerConfiguration(AliEngineCameraCapturerConfiguration cameraCapturerConfiguration);This method configures capture preferences, such as camera direction and frame rate.
When to call
You must call this method before turning on the camera, for example, before performing the following operations:
startPreview (starts the video preview)
joinChannel (joins a channel)
Parameters
|
Parameter |
Type |
Description |
|
cameraCapturerConfiguration |
Camera capture preferences, such as camera direction and frame rate. Default values:
"-1" indicates using the SDK’s default settings. |
Return Description
A return value of 0 indicates that the method call was successful. Any other value indicates a failure.
enableLocalVideo
Disables or re-enables local video capture.
public abstract int enableLocalVideo(boolean enable);This method controls enabling and disabling local video capture. When local video capture is disabled, there is no video data for local preview or stream ingest, but it does not affect receiving remote video. If you call this method to disable local camera capture, both local preview and remote stream ingest remain on the last frame.
Local video capture is enabled by default in the SDK.
When to call
You can call this method before or after joining a channel.
Related callbacks
A successful call to this API notifies the remote user through the onUserVideoEnabled callback.
Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean |
Specifies whether to disable or re-enable local video collection. Valid values:
|
Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure.
muteLocalCamera
Stops or resumes sending local video data.
public abstract int muteLocalCamera(boolean mute, AliRtcVideoTrack track);When ingesting streams, you can call this method to send entirely black video frames. Local preview remains normal, and capture, encoding, and sending modules continue to operate, but the video content consists of black frames.
This API only controls whether to send black frames on the specified video stream. Video capturing and data sending will not stop. To stop capturing, use enableLocalVideo. To abort video data sending, use publishLocalVideoStream or invoke <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7558afe6accq4" id="ee17216e55r3t">enableLocalVideo</a> stop capturing.
Parameters
|
Parameter |
Type |
Description |
|
mute |
boolean |
Stops or resumes publishing the local video track. Valid values:
|
|
track |
The video stream type for which you want to change the publish state. |
Return Description
A value of 0 indicates that the call is successful.
isCameraOn
Checks if the camera is on.
public abstract boolean isCameraOn();Return Description
A value of true indicates the camera is on. A value of false indicates the camera is off.
setVideoEncoderConfiguration
Sets video encoding properties.
public abstract void setVideoEncoderConfiguration(AliRtcVideoEncoderConfiguration config);This method sets video encoding properties for the video stream, such as resolution, frame rate, bitrate, and video orientation. We recommend that you call this method for all video scenarios.
Each parameter has a valid range. If you set a parameter to a value outside its valid range, the SDK automatically adjusts the value to be within the range.
When to call
You can call this method before or after joining 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 joining the channel.
Limitations
The mirrorMode parameter of this method and the setVideoMirrorMode method both set the mirroring for video stream ingest. We recommend that you use only one of these methods. Using both methods can cause mirroring effects to overlap, which can lead to mirroring failures or inconsistencies.
Parameters
|
Parameter |
Type |
Description |
|
config |
Predefined encoding properties. Default values:
A value of -1 indicates using the SDK's internal default settings. |
setVideoDecoderConfiguration
Sets video decoding properties.
public abstract void setVideoDecoderConfiguration(AliRtcVideoDecoderConfiguration config);This method sets the video parameters for decoding a video stream.
When to call
We recommend calling this method before joining a channel.
Parameters
|
Name |
Type |
Description |
|
config |
AliRtcVideoDecoderConfiguration |
Predefined decoding properties. Default values:
A value of -1 means using the SDK's internal default settings. |
switchCamera
You can switch between the front and rear cameras. The front camera is used by default.
public abstract int switchCamera();This method controls whether the front-facing or rear-facing camera is used. By default, the front-facing camera is used. You can dynamically switch between cameras during app runtime, based on the available cameras, without restarting the video stream or reconfiguring the video source.
When to call
You can call this method only after the camera is successfully enabled.
Limitations
This method is only supported on Android and iOS.
Return description
A value of 0 indicates that the call succeeded. Any other value indicates that it failed.
getCurrentCameraDirection
Retrieves the current camera direction.
public abstract AliRTCCameraDirection getCurrentCameraDirection();Return Instructions
A value of CAMERA_REAR (0) indicates the rear camera.
A value of CAMERA_FRONT (1) indicates the front camera.
A value of CAMERA_INVALID (-1) indicates an invalid value.
You can call this method only after the camera is enabled. Otherwise, it returns CAMERA_INVALID (-1).
startPreview
Start the local preview.
public abstract int startPreview();This method starts a local video preview and automatically enables the camera. To stop the local preview, you can call the stopPreview method.
leaveChannel Leaving the channel automatically stops local preview. If you are not publishing a camera stream, the camera shuts down.
Invocation timing
You must set a view for the local preview by calling setLocalViewConfig before the call. Otherwise, the preview will not be displayed, but stream ingest is not affected.
If needed, you can call this method to start preview before calling joinChannel. The camera automatically turns on.
Return description
A value of 0 indicates a successful call, while any other value indicates failure.
stopPreview
Stops the local preview.
public abstract int stopPreview();This method stops the local video preview and turns off the camera. After the preview is stopped, the local view displays the last captured frame, and stream ingest is not affected.
When you call leaveChannel, the local preview stops automatically. If you are not publishing a camera stream, the camera is also turned off automatically.
When to call
You can call this method after starting the local preview.
Return Description
A return value of 0 indicates success. Any other value indicates failure.
setCameraZoom
You can set the camera zoom ratio.
public abstract int setCameraZoom(float zoom);You can set the zoom factor of the camera.
Limitations
This method is available only on iOS and Android devices.
When to call
This setting takes effect only after you enable the camera. The zoom resets each time the camera restarts.
Parameters
|
Parameter |
Type |
Description |
|
zoom |
float |
The camera zoom factor. The value ranges from 1 to the maximum zoom value that the camera supports. Call GetCameraMaxZoomFactor to get the maximum zoom factor for the current device. |
Return Description
0: call succeeded.
Non-zero: the method call failed.
GetCameraMaxZoomFactor
Retrieves the maximum zoom factor (optical zoom) supported by the camera.
public abstract float GetCameraMaxZoomFactor();Return Description
The maximum zoom factor supported by the device camera.
GetCurrentZoom
You can retrieve the current camera zoom factor setting.
public abstract float GetCurrentZoom();Return Description
The current camera zoom factor of the device.
SetExposure
You can set the camera exposure.
public abstract int SetExposure(float exposure);When the shooting environment is too dark or too bright, video capture quality is affected. To improve video quality, you can use this method to adjust your camera's exposure level. You can retrieve the supported exposure level range using GetMinExposure and GetMaxExposure.
Parameters
|
Parameter |
Type |
Description |
|
Exposure |
float |
The camera's exposure value. The default value is 0. This means the camera uses its default exposure. A higher value increases the exposure. If the video image is overexposed, decrease the exposure value. If the video image is underexposed and dark details are lost, increase the exposure value. If the provided exposure value is outside the device's supported range, the SDK adjusts it automatically. |
Response description
0: call succeeded.
A non-zero value indicates that the method call failed.
GetCurrentExposure
Retrieves the exposure level of the camera.
public abstract float GetCurrentExposure();Retrieves the exposure level setting of the camera currently in use.
Return description
The current exposure level of the camera.
GetMinExposure
You can obtain the minimum exposure supported by the camera.
public abstract float GetMinExposure();Return description
The minimum camera exposure level.
GetMaxExposure
Retrieves the maximum supported camera exposure level.
public abstract float GetMaxExposure();Return Description
The maximum camera exposure level.
setCameraFlash
Enables or disables the camera flash.
public abstract int setCameraFlash(boolean flash);Enables or disables the flash.
Typically, only rear-facing cameras support flash functionality.
Limitations
This method is supported only on iOS and Android.
Parameters
|
Parameter |
Type |
Description |
|
flash |
boolean |
Enable the flash.
|
Return Description
0: The setting succeeded.
A non-zero value: The setting failed.
isCameraFocusPointSupported
Queries whether manual focus is supported on the current device.
public abstract boolean isCameraFocusPointSupported();Checks whether the current camera supports setting a focus point for manual focus.
Limitations
This method is available only on iOS and Android.
Response description
true: The device supports manual focus.
false: The device does not support manual focus.
isCameraExposurePointSupported
Checks if setting the camera exposure point is supported.
public abstract boolean isCameraExposurePointSupported();Determines if an exposure point can be set on the current device.
Limitations
This method is available only on iOS and Android.
Return Description
true: The camera exposure point can be set.
false: The camera exposure point cannot be set.
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 operation, the camera adjusts the exposure for the specified point and then maintains this focus value. Before you call this operation, we recommend that you call isCameraFocusPointSupported to check whether the device supports manual focus.
Limitations
This method is available only on iOS and Android.
Call this method only before joining a channel.
|
Parameter |
Type |
Description |
|
x |
float |
The x-coordinate value. |
|
y |
float |
The value on the y-axis. |
Return Description
0: call succeeded.
Non-zero: call failed.
setCameraExposurePoint
You can set the camera exposure point.
public abstract int setCameraExposurePoint(float x, float y);This operation sets the camera exposure point. After you call it, the camera adjusts the exposure once for the specified point and maintains that exposure value. Before calling this operation, we recommend that you call isCameraExposurePointSupported to check whether the device supports manual exposure point setting.
Limitations
This method is available only on iOS and Android devices.
Parameters
|
Parameter |
Type |
Description |
|
x |
float |
X-axis coordinate value |
|
y |
float |
y-axis coordinate value |
Return Description
0: The method call succeeded.
Non-zero: The method call failed.
isCameraAutoFocusFaceModeSupported
Checks if 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. It returns true if the camera is enabled and supports both face detection and auto focus. Otherwise, it returns false.
Limitations
This method is available only on iOS and Android.
Return description
true: Automatic face focus is supported.
false: Automatic face focus is not supported.
setCameraAutoFocusFaceModeEnabled
You can set the camera's face focus.
public abstract boolean setCameraAutoFocusFaceModeEnabled(boolean enable);This interface enables real-time autofocus on human faces. Before calling this method, you must call isCameraAutoFocusFaceModeSupported to verify device support for this feature.
Limitations
This method is available only on iOS and Android.
Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean |
Turn the camera face focus feature on or off.
|
Return description
true: The call succeeded.
false: The call failed.
setVideoMirrorMode
Configure video mirroring for preview and stream ingest.
public abstract int setVideoMirrorMode(AliRtcVideoPipelineMirrorMode mirrorMode);Specifies whether to enable mirroring mode for local preview video and ingested video streams.
This interface takes precedence over setLocalViewConfig and setVideoEncoderConfiguration. To set the video mirroring mode, you can call this interface.
When to call
You can dynamically set this method before or after joining a channel. The SDK records the state internally and applies video operations when preview and encoding (stream ingest) are available.
Call Limits
This method overlaps with mirrorMode in setLocalViewConfig and setVideoEncoderConfiguration. We recommend using only one of these methods.
Call this method before joining a channel.
|
Parameter |
Type |
Description |
|
mirrorMode |
Sets the mirror mode. |
Response description
0: The setting was applied successfully.
<0: Settings failed.
AliRtcErrInner: SDK internal state error. You can check if the SDK instance was created successfully.
setCapturePipelineScaleMode
Sets the timing of video capture scaling.
public abstract void setCapturePipelineScaleMode(AliRtcCapturePipelineScaleMode mode);Sets whether video data capture scaling occurs immediately upon capture or during encoding. For example, when capture resolution differs from encoding resolution, you can set the scaling timing to determine if preview data and stream ingest data are consistent.
When to call
Set this method before enabling the camera. For example, set it before starting preview with startPreview or joining a channel with joinChannel.
Parameters
|
Parameter |
Type |
Description |
|
mode |
AliRtcCapturePipelineScaleMode |
This mode controls the timing of collection scaling. By default, scaling occurs immediately upon collection. |
Return Description
None.
setExternalVideoSource
Enables an external video input source.
public abstract void setExternalVideoSource(boolean enable,boolean useTexture,
AliRtcVideoTrack streamType,AliRtcRenderMode renderMode);Parameters
|
Parameter |
Type |
Description |
|
enable |
boolean |
Specifies whether to enable the external video input source. Valid values:
|
|
useTexture |
boolean |
Specifies whether to use the texture mode.
|
|
type |
Video stream type. | |
|
renderMode |
Rendering mode. |
pushExternalVideoFrame
Imports video data.
public abstract int pushExternalVideoFrame(AliRtcRawDataFrame aliRawDataFrame,AliRtcVideoTrack streameType);Parameters
|
Parameter |
Type |
Description |
|
aliRawDataFrame |
The frame data. | |
|
streameType |
Video stream type. |
Response description
A value of 0 indicates that the call is successful. Any other value indicates failure.
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. |
Response description
A value of 0 indicates that the call succeeded. Any other value indicates failure.
updatePublishLiveStream
You can update the bypass live streaming parameters.
public abstract int updatePublishLiveStream(String streamUrl,AliRtcLiveTranscodingParam transcodingParam);Parameters
|
Parameter |
Type |
Description |
|
streamUrl |
String |
The ingest URL. |
|
transcodingParam |
The stream ingest parameters. |
Return instructions
A value of 0 indicates success. Any other value indicates failure.
stopPublishLiveStream
Stop the bypass live stream.
public abstract int stopPublishLiveStream(String streamUrl);Parameters
|
Parameter |
Type |
Description |
|
streamUrl |
String |
The ingest URL. |
Return description
A value of 0 indicates success. Any other value indicates failure.
getPublishLiveStreamState
Retrieve the bypass live streaming status.
public abstract AliRtcEngine.AliRtcLiveTranscodingState getPublishLiveStreamState(String streamUrl);Parameters
|
Parameter |
Type |
Note |
|
streamUrl |
String |
The ingest URL for bypass live streaming. |
Return Instructions
Returns the status of bypass live streaming.
startNetworkQualityProbeTest
You can enable network quality probing.
public abstract int startNetworkQualityProbeTest(AlirtcNetworkQualityProbeConfig config);Parameters
|
Parameter |
Type |
Description |
|
config |
AlirtcNetworkQualityProbeConfig |
The parameters of the probe configuration. |
Return description
A value of 0 indicates success, while a non-zero value indicates failure.
stopNetworkQualityProbeTest
Stops network quality testing.
public abstract int stopNetworkQualityProbeTest();Return Description
A value of 0 indicates success. Any other value indicates failure.
sendMediaExtensionMsg
You can send media extension information.
public abstract int sendMediaExtensionMsg(byte[]message, int repeatCount, int delay, boolean isKeyFrame);The SDK lets you send and receive media extension messages. The sending method uses the SEI extension protocol. Receivers can obtain the messages by listening for the onMediaExtensionMsgReceived event.
Common use cases include the following:
Use media extension information to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business operations.
Use media extension information to transmit descriptive information. You can transmit up to 4 KB of data, which is suitable for small amounts of data. We recommend using JSON or plain strings.
When to call
You can call this method after starting stream ingest.
Limitations
Using media extension information requires reusing the audio and video data channel. Therefore, you must control how frequently you send custom messages and the length of the message data. The limitations are as follows:
You can send up to fps messages per second, as specified in the profile, because SEI information is embedded in H.264 or H.265 streams and requires video frame encoding to attach extension information.
To avoid impacting media data transmission quality, the custom message body is limited to 4 KB, making it suitable for small amounts of information.
The repeatCount parameter in the sendMediaExtensionMsg function specifies the redundancy level for custom messages. If this value is greater than 1, the message is sent multiple times.
This redundancy helps prevent message loss caused by network packet loss. In such cases, other participants in the room receive multiple identical messages and must deduplicate them.
Subscribers in the room also receive custom messages during relayed live streaming.
Only one MediaExtensionMsg is transmitted at a time. Multiple calls to sendMediaExtensionMsg overwrite previously queued data.
Related callbacks
The stream puller can retrieve media extension information sent by the stream ingestor by listening for the onMediaExtensionMsgReceived callback.
Parameters
|
Parameter |
Type |
Description |
|
message |
byte[] |
Media extension information. The maximum length is 4 KB. |
|
repeatCount |
int |
The repetition count indicates message redundancy. It prevents message loss caused by network packet loss. A value of -1 means infinite transmission. |
|
Delay |
int |
Delay in milliseconds. This is the minimum time to wait after calling the API before sending extension information. |
|
isKeyFrame |
boolean |
Specifies whether to attach extension information only to keyframes. A value of true attaches the information only to keyframes. |
Return Instructions
0: The call succeeded.
<0: The call failed. An error code is returned.
ERR_INNER(-1): Internal SDK error. Possible causes: The SDK is not initialized, or it is called after it has been destroyed.
sendMediaExtensionMsgEx
Sends media extension information.
public abstract int sendMediaExtensionMsgEx(byte[]message, int repeatCount, int delay, boolean isKeyFrame, int payloadType);The SDK provides a feature to send and receive media extension information. This method sends media extension information using the SEI extension protocol. You can obtain the information by listening to onMediaExtensionMsgReceived. When payloadType is 5, this is equivalent to using the sendMediaExtensionMsg interface.
Common use cases include the following:
Use media extension information to transmit timestamps, calculate end-to-end network latency, or synchronize data with other business operations.
Use media extension information to transmit descriptive information. You can transmit up to 4 KB of data, which is suitable for small amounts of data. We recommend using JSON or plain strings.
When to call
You can call this method after you start stream ingest.
Limitations
Using media extension information requires reusing the audio and video data channel. Therefore, you must control how frequently you send custom messages and the length of the message data. The limitations are as follows:
You can send up to fps messages per second, as specified in the profile, because SEI information is embedded in H.264 or H.265 streams and requires video frame encoding to attach extension information.
To avoid degrading media data transmission quality, the custom message body is limited to 4 KB, making it suitable for small amounts of information.
The repeatCount parameter in the sendMediaExtensionMsg function specifies the redundancy level for custom messages. If this value is greater than 1, the message is sent multiple times.
This redundancy helps prevent message loss caused by network packet loss. In such cases, other participants in the room receive multiple identical messages and must deduplicate them.
Subscribers in the room also receive custom messages during relayed live streaming.
Only one MediaExtensionMsg is transmitted at a time. Multiple calls to sendMediaExtensionMsg overwrite previously queued data.
Parameter description
|
Parameter |
Type |
Description |
|
Message |
byte[] |
Media extension information. Maximum length: 4 KB. |
|
repeatCount |
int |
Repeat count, which represents message redundancy to prevent message loss caused by network packet loss. A value of -1 means infinite transmission. |
|
Delay |
int |
Delay, in milliseconds. This is the shortest time to send extension data after an API call. |
|
isKeyFrame |
boolean |
Only keyframes use extension information. If true, extension information is attached only to keyframes. |
|
payloadType |
int |
The range [5, 100..254] for payloadType=5 is equivalent to using the sendMediaExtensionMsg interface. |
Return description
0: The call succeeded.
<0: The call failed and returns an error code.
ERR_INNER(-1): An SDK internal error occurred. Possible causes include SDK initialization failure or calling the SDK after it has been destroyed.
onConnectionStatusChange
This callback is invoked when the network connection status changes. It is important to monitor this callback.
public void onConnectionStatusChange(AliRtcEngine.AliRtcConnectionStatus status,
AliRtcEngine.AliRtcConnectionStatusChangeReason reason);Parameters
|
Parameter |
Type |
Description |
|
status |
The current network connection status. | |
|
reason |
Reason for network connection status change. |
OnLocalDeviceException
The callback that is invoked when a local device exception occurs. Pay close attention to this callback.
public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg)Parameters
|
Parameter |
Type |
Description |
|
deviceType |
AliRtcEngineLocalDeviceType |
Device type |
|
exceptionType |
AliRtcEngineLocalDeviceExceptionType |
The device exception type. |
|
msg |
String |
The information carried in the exception. |
onAuthInfoWillExpire
This callback indicates that the user authentication will expire in 30 seconds. You must handle this callback.
public void onAuthInfoWillExpire();This callback indicates that the user's authentication information will expire in 30 seconds. You must obtain a new token and update the authentication information using one of the following methods:
Call
<a baseurl="t2309760_v6_4_1.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#975b9af9ecq1a" id="8099ac5a509hn">refreshAuthInfo</a>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 Time
The SDK triggers this callback 30 seconds before the user's authentication information expires. When you receive this callback, you must update the authentication information promptly.
onAuthInfoExpired
The user invokes an interface that requires authentication, and the server returns expired information.
public void onAuthInfoExpired();This callback indicates that the user's authentication information has expired. If you want to remain in the session, you must generate a new token on the server and then update the authentication information using the following method:
You can call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="c3b0cf2f19dgm">leaveChannel</a>to exit the current channel. Then, calljoinChannelto re-enter it.
Trigger time
This callback is triggered when the user's 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 the request to join the channel. A value of 0 indicates success. A non-zero value indicates an error code. For more information, see Error codes. The following are common error codes:
|
|
channel |
String |
The channel ID. |
|
userId |
String |
User ID. |
|
elapsed |
int |
The time it takes to join the channel. Unit: milliseconds. |
onLeaveChannelResult
The callback that returns the result of leaving a channel.
public void onLeaveChannelResult(int result, AliRtcEngine.AliRtcStats stats);Triggering conditions
This callback is triggered when the application successfully calls <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="7f3d2133c81tx">leaveChannel</a> and the system returns the result of leaving the channel along with the session statistics information.
If you call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="fdccda828dzqt">leaveChannel</a> and then immediately call destroy to destroy the engine, this callback is not triggered.
Parameters
|
Parameter |
Type |
Description |
|
result |
int |
The result of leaving the channel. A value of 0 indicates success. A non-zero value indicates an error code if the operation fails. |
|
stats |
Data statistics for the session in this channel. |
onRemoteUserOffLineNotify
Offline callback for a remote user.
public void onRemoteUserOffLineNotify(String uid, AliRtcUserOfflineReason reason);This callback notifies the local user that a remote user has left the channel because they went offline.
Trigger conditions
When a remote user actively leaves the channel, the callback is triggered.
When a remote streamer calls
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="4c0adbe948tif">setClientRole</a>to switch to the viewer role (by calling AliRtcEngine#setClientRole and setting the role to AliRTCSdkLive), the callback is triggered.When a remote streamer is considered offline because no data is received from them for an extended period, the callback is triggered.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
reason |
The reason the user went offline. |
onRemoteUserOnLineNotify
This callback is invoked when a remote user comes online.
public void onRemoteUserOnLineNotify(String uid, int elapsed);This method notifies the local client that a remote user has joined the channel.
Triggering conditions
A remote user joins the channel.
After the local user joins the channel, this callback is invoked for each user who is already in the channel. This allows the local user to identify the existing users.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
elapsed |
int |
The time it takes for a user to join the channel. Unit: milliseconds. |
onRemoteTrackAvailableNotify
This callback is invoked when a remote user's audio and video streams change.
public void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack,
AliRtcVideoTrack videoTrack);This callback is triggered when a remote user's stream ingest status changes. Through this callback, developers can obtain real-time information about whether remote users are ingesting audio and video streams, and accordingly display or hide the remote users' audio and video information.
This callback returns the remote user's stream ingest status. To determine which stream went offline during this change, record the status changes before and after the callback.
Triggering conditions
This callback is triggered in the following scenarios:
When a remote user changes from not ingesting streams to ingesting streams (including audio and video).
When the remote user stops streaming both audio and video.
In interactive mode, this callback is triggered when a remote user calls setClientRole to switch from the viewer role to the streamer role and configures stream ingest.
For example, for video, this callback is not triggered if the remote user does not perform stream ingest.
When a remote user starts ingesting a camera stream (stream ingest status: no video stream -> camera stream only), the local callback returns
AliRtcVideoTrackCamera, indicating the remote user's camera stream is available.When a remote user also ingests a screen-sharing stream (stream ingest status: camera stream only -> camera stream and screen-sharing stream), the local callback returns
AliRtcVideoTrackBoth, indicating both the remote user's camera stream and screen-sharing stream are available.When a remote user stops ingesting the camera stream and retains only the screen-sharing stream (stream ingest status: camera stream and screen-sharing stream -> screen-sharing stream only), the local callback returns
AliRtcVideoTrackScreen, indicating only the screen-sharing stream is currently available.When a remote user stops ingesting the screen-sharing stream (stream ingest status: screen-sharing stream only -> no video stream), the local callback returns
AliRtcVideoTrackNo, indicating no video stream is currently available.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
audioTrack |
The remote user's audio stream after a change. | |
|
videoTrack |
The remote user's video stream after the change. |
onBye
The callback that is invoked when a user is forced to leave a channel or the channel is closed.
public void onBye(int code);This callback is triggered when a user is disconnected or a session ends. You can use the code parameter to determine the reason for the disconnection and handle it accordingly.
Triggering conditions
The current user is kicked out by the server.
The session ends because the server closes the channel.
An unexpected disconnection occurs, which requires the client to attempt to restore the session or reconnect.
Parameters
|
Parameter |
Type |
Description |
|
code |
int |
The reason a user is removed from the channel. For more information, see AliRtcOnByeType. |
onAudioPublishStateChanged
This callback is invoked when the audio 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.
Triggering conditions
This callback is triggered when the user's audio stream ingest status changes, such as:
The user stops stream ingest.
The user calls
<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 a viewer.
Parameters
|
Parameter |
Type |
Description |
|
oldState |
The previous state of the stream ingest. | |
|
newState |
The current stream ingest state. | |
|
elapseSinceLastState |
int |
The interval between state changes. Unit: milliseconds. |
|
channel |
String |
The ID of the channel. |
onAudioSubscribeStateChanged
The callback that is invoked when the audio subscription status changes.
public void onAudioSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback notifies the local user of changes to the subscription status of a remote user's audio stream. It also reports changes to the subscription status of a remote user's camera stream and provides the time elapsed between the previous and current states.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
Remote user ID. |
|
oldState |
The previous subscription state. | |
|
newState |
The current subscription state. | |
|
elapseSinceLastState |
int |
State change time interval. Unit: milliseconds. |
|
channel |
String |
The current channel ID. |
onUserAudioMuted
A notification is sent when the remote user stops sending audio data.
public void onUserAudioMuted(String uid ,boolean isMute);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the user who mutes the audio track. |
|
isMute |
boolean |
Indicates whether the audio track is 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 is interrupted. |
onUserAudioInterruptedEnded
A notification is sent when a user's audio interruption ends.
public void onUserAudioInterruptedEnded(String uid);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the user whose audio track is interrupted. |
onVideoPublishStateChanged
Callback for video stream ingest changes.
public void onVideoPublishStateChanged(AliRtcEngine.AliRtcPublishState oldState ,
AliRtcEngine.AliRtcPublishState newState,
int elapseSinceLastState, String channel);This callback monitors the local user's video stream ingest status for changes.
Parameters
|
Parameter |
Type |
Description |
|
oldState |
The previous stream ingest state. | |
|
newState |
The current stream ingest state. | |
|
elapseSinceLastState |
int |
The time interval between state changes. Unit: milliseconds. |
|
channel |
String |
The ID of the channel. |
onVideoSubscribeStateChanged
This callback is invoked when the camera stream subscription status changes.
public void onVideoSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback notifies the local user of changes in a remote user's camera stream subscription status. Through this callback, you can obtain information about changes in a specific remote user's camera stream subscription status and the time interval between the previous and current states.
Related callbacks
Video streams include camera streams and screen-sharing streams. This method handles camera stream subscription status changes. The related callback for screen-sharing streams is onScreenShareSubscribeStateChanged.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The remote user ID. |
|
oldState |
The previous subscription state. | |
|
newState |
The current subscription state. | |
|
elapseSinceLastState |
int |
The time interval between status changes. |
|
channel |
String |
The current channel ID. |
onUserVideoMuted
The peer user sends a notification when transmitting video black frames.
public void onUserVideoMuted(String uid, boolean isMute);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The user executing enableLocalVideo. |
|
isMute |
boolean |
Specifies whether to send black frames. Valid values:
|
onUserVideoEnabled
A notification is sent when the remote user stops the camera stream.
public void onUserVideoEnabled(String uid, boolean isMute);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
isMute |
boolean |
Enables camera track collection. Valid values:
|
onUserWillResignActive
This callback is invoked when a remote user's application moves to the background.
public void onUserWillResignActive(String uid);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
User ID. |
onUserWillBecomeActive
The remote user's application returns to the foreground.
public void onUserWillBecomeActive(String uid);Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The user ID. |
onAliRtcStats
This callback is triggered every two seconds to report statistics for the current session.
public void onAliRtcStats(AliRtcEngine.AliRtcStats stats);Parameters
|
Parameter |
Type |
Description |
|
stats |
Session statistics. |
onAudioEffectFinished
This callback is invoked when a local sound effect finishes playing.
void OnAudioEffectFinished(int soundId);Parameters
|
Parameter |
Type |
Description |
|
soundId |
int |
The ID assigned by the user to the sound effect file. |
onAudioFileInfo
Callback for audio file information.
public void onAudioFileInfo(AliRtcEngine.AliRtcAudioFileInfo info, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);When you call getAudioFileInfo, this callback is triggered and returns information such as the audio file duration or an error message.
Parameters
|
Parameter |
Type |
Description |
|
Information |
AliRtcEngine.AliRtcAudioFileInfo |
Audio file information, including the file path and duration. |
|
errorCode |
AliRtcEngine.AliRtcAudioAccompanyErrorCode |
Audio accompaniment error codes, primarily indicating file open failures or file decoding failures. |
onMediaExtensionMsgReceived
This callback is invoked when media extension information is received.
public void onMediaExtensionMsgReceived(String uid, int payloadType, byte[]message);When an endpoint calls sendMediaExtensionMsg to send a message, other endpoints receive the data through this callback.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
User ID. The ID of the user who sends the media information. |
|
payloadType |
int |
Payload type. `sendMediaExtensionMsg` returns 5. `sendMediaExtensionMsgEx` returns a specific type. |
|
Message |
byte[] |
Media extension information. |
onFirstRemoteVideoFrameDrawn
This callback is invoked when the first video frame from a remote user is rendered.
public void onFirstRemoteVideoFrameDrawn(String uid,AliRtcVideoTrack videoTrack, int width, int height, int elapsed);This callback indicates the rendering of the first remote video frame. It is triggered when the local user successfully receives and renders the first video frame from a remote user. This callback helps developers monitor the establishment time of the remote video link, evaluate network and device performance, and optimize the user experience.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
videoTrack |
The type of video stream to accept. | |
|
Width |
int |
Width of the pulled video stream. |
|
Height |
int |
The height of the pulled video stream. |
|
elapsed |
int |
Total delay in milliseconds from when a local user joins the channel until the first frame of the pulled stream video appears. |
onFirstLocalVideoFrameDrawn
This callback is invoked when the first local video frame is rendered during a preview.
public void onFirstLocalVideoFrameDrawn(int width, int height, int elapsed);This callback is triggered after the local camera is enabled and the first video frame is rendered. You can use this callback to monitor the rendering speed of the local video preview, evaluate device performance, and optimize the user experience, such as displaying a "Camera ready" message or adjusting the preview layout.
Parameters
|
Parameter |
Type |
Description |
|
width |
int |
Width of the local preview video. |
|
height |
int |
The height of the local video preview. |
|
Elapsed |
int |
The total time elapsed (in milliseconds) from when the local user joins a channel until the local preview displays the first frame. |
onFirstVideoFrameReceived
This callback is invoked when the first video frame from a remote user is received.
public void onFirstVideoFrameReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost);You can use this callback to monitor the video link establishment time, evaluate network quality, and optimize the user experience. For example, you can display a "Video ready" message or adjust the playback logic.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
videoTrack |
The type of video stream to accept. | |
|
timeCost |
int |
Time to send the first video packet, measured in milliseconds from when a user joins the meeting. |
onFirstVideoPacketSent
This callback is invoked when the first video packet is sent.
public void onFirstVideoPacketSent(String uid, AliRtcVideoTrack videoTrack, int timeCost);This callback is triggered when the local user successfully sends the first video data packet. It helps developers monitor the establishment speed of the video sending link, evaluate local device performance, and optimize the user experience, such as by displaying "Video sent" or adjusting the capture policy.
Parameters
|
Parameter |
Type |
Description |
|
UID |
String |
The ID of the remote user. |
|
videoTrack |
Accept video stream types. | |
|
timeCost |
int |
The time from joining the meeting to sending the first video packet. This is measured in milliseconds. |
onFirstAudioPacketSent
This callback is invoked when the local user successfully sends the first audio packet.
public void onFirstAudioPacketSent(String uid, AliRtcAudioTrack track, int timeCost);Developers can use this callback to monitor how quickly the audio sending link is established, evaluate local device and system performance, and optimize the user experience.
Parameters
|
Parameters |
Type |
Description |
|
UID |
String |
Remote user ID. |
|
track |
Accepts audio stream types. | |
|
timeCost |
int |
Sending duration: The time elapsed from joining a session until the first audio packet is sent. Unit: milliseconds. |
onFirstVideoPacketReceived
This callback is invoked when the first video packet is received.
public void onFirstVideoPacketReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost)This callback indicates the reception of the first remote video packet. It is triggered when the local user receives the first video packet from a remote user. Developers can use this callback to monitor the establishment speed of the video link or update the UI components of the playback stream.
Parameters
|
Parameters |
Type |
Description |
|
uid |
String |
Remote user ID. |
|
video track |
Video stream type to accept. | |
|
timeCost |
int |
The time from when the local user joins a channel to receiving the first video package (in milliseconds). |
onFirstAudioPacketReceived
This callback is triggered when the first audio packet from a remote user is received.
public void onFirstAudioPacketReceived(String uid, AliRtcAudioTrack track, int timeCost)This callback is triggered to notify the local user when the first audio data packet is received from a remote user. It helps developers monitor the speed of audio link establishment, evaluate network quality, and optimize the user experience—for example, by displaying an "Audio connected" prompt or adjusting the playback policy.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
|
track |
Accept audio stream type. | |
|
timeCost |
int |
The time, in milliseconds, from when the local user joins a channel to receiving the first audio packet. |
onFirstRemoteAudioDecoded
This callback is invoked when the first audio frame from a remote user has been decoded and is ready for playback.
public void onFirstRemoteAudioDecoded(String uid, AliRtcAudioTrack track, int elapsed)This callback indicates that the remote audio stream is ready. You can use this callback to calculate the time to the first frame or update UI components.
Parameters
|
Parameter |
Type |
Description |
|
UID |
String |
The remote user ID. |
|
track |
Audio stream type. | |
|
elapsed |
int |
The latency from when the local user joins a channel until the first audio frame is decoded (in milliseconds). |
onAudioAccompanyStateChanged
This callback is invoked when the local audio accompaniment playback state changes.
public void onAudioAccompanyStateChanged(AliRtcEngine.AliRtcAudioAccompanyStateCode playState, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);This callback reports local accompaniment playback state changes. It notifies developers in real-time about the current accompaniment playback state (such as start, pause, or end) and any associated error codes. Developers can use this callback to monitor playback progress, handle exceptions, and update the user interface.
Parameters
Parameter |
Type |
Description |
|
playState |
AliRtcEngine.AliRtcAudioAccompanyStateCode |
Playback status of the accompaniment. |
|
errorCode |
AliRtcEngine.AliRtcAudioAccompanyErrorCode |
Playback error codes primarily indicate errors when opening or decoding files. |
onRemoteAudioAccompanyStarted
The callback that is invoked when a remote user starts audio accompaniment playback.
public void onRemoteAudioAccompanyStarted(String uid);This callback notifies the local application when a remote user begins playing audio accompaniment, such as background music. You can use this callback to execute initialization logic—for example, update the UI, adjust the volume, or notify other users.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user who started the accompaniment playback. |
onRemoteAudioAccompanyFinished
This callback is invoked when a remote user finishes playing audio accompaniment.
public void onRemoteAudioAccompanyFinished(String uid);It 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 the status.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user when the backing track playback ends. |
onVideoResolutionChanged
The resolution of the remote video changes.
public void onVideoResolutionChanged(String uid,AliRtcVideoTrack videoTrack, int width, int height);This callback notifies you of changes in the resolution of a remote user’s video stream. It is triggered when the remote user switches cameras, adjusts video clarity, or experiences resolution degradation due to network fluctuations. You can use this callback to dynamically adjust local video rendering logic, such as UI layout, canvas scaling, or performance optimization.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
Remote user ID whose resolution changes. |
|
videoTrack |
The type of video stream, such as a camera stream or a screen stream. | |
|
width |
int |
New video resolution width. |
|
height |
int |
The new video resolution height. |
onRtcLocalVideoStats
A callback that provides statistics for locally published video streams.
public void onRtcLocalVideoStats(AliRtcEngine.AliRtcLocalVideoStats aliRtcStats);This callback delivers real-time information about the local video stream’s encoding and transmission status, such as bitrate and frame rate. You can use it to monitor video quality, diagnose performance issues, or dynamically adjust encoding parameters.
Parameters
|
Parameter |
Type |
Description |
|
aliRtcStats |
AliRtcEngine.AliRtcLocalVideoStats |
Performance statistics for local video pushes, including the publish bit rate and frame rate. For more information, see AliRtcLocalVideoStats. |
onRtcRemoteVideoStats
This callback provides statistics for remotely subscribed video streams.
public void onRtcRemoteVideoStats(AliRtcEngine.AliRtcRemoteVideoStats aliRtcStats);This callback provides real-time data statistics for remote video streams. It retrieves real-time information about the remote video's encoding and transmission status, such as bitrate, frame rate, resolution, latency, and stuttering. Developers can use this callback to monitor video quality, diagnose performance issues, or dynamically adjust decoding parameters.
Parameters
|
Parameter |
Type |
Description |
|
aliRtcStats |
AliRtcEngine.AliRtcRemoteVideoStats |
Pull remote video performance statistics, including remote user ID, video resolution, frame rate, stuttering count, and other information. For more information, see AliRtcRemoteVideoStats. |
onRtcRemoteAudioStats
Data statistics for the subscribed remote audio stream.
public void onRtcRemoteAudioStats(AliRtcEngine.AliRtcRemoteAudioStats aliRtcStats);This callback provides real-time statistics about a remote audio stream, such as audio quality, packet loss rate, and latency. You can use this callback to monitor the stability of the remote audio connection, diagnose network issues, and dynamically adjust playback policies, such as enabling noise reduction or prompting users to optimize their network.
Parameters
|
Parameter |
Type | Description |
|
aliRtcStats |
AliRtcEngine.AliRtcRemoteAudioStats |
Pull statistics for remote audio. These statistics include the remote user ID, audio quality, packet loss rate, number of stutters, and latency. For more information, see AliRtcRemoteAudioStats. |
onRtcLocalAudioStats
Reports statistics of the published local audio stream.
public void onRtcLocalAudioStats(AliRtcEngine.AliRtcLocalAudioStats aliRtcStats);This callback provides real-time statistics for local audio stream ingest, including encoding and transmission status such as bitrate, sample rate, number of sound channels, and packet loss rate. You can use this callback to monitor the stability of the local audio link, diagnose performance issues, and dynamically adjust encoding policies—for example, by reducing the bitrate.
Parameters
|
Parameter |
Type |
Description |
|
aliRtcStats |
AliRtcEngine.AliRtcLocalAudioStats |
Performance statistics for the local audio push, including the audio stream type, send bitrate, send sample rate, and the number of sound channels. For more information, see AliRtcLocalAudioStats. |
onAudioFocusChange
The callback that is invoked when audio focus changes (Android only).
public void onAudioFocusChange(int focusChange);Notifications for audio focus changes. By default, the SDK automatically requests audio focus. If your application needs to use audio focus again, you must request it again in the (callback) that the SDK triggers when audio focus changes.
Notification timing
This callback is triggered when the audio output device changes, such as when you plug or unplug headphones, switch to a different Bluetooth device, or switch between the earpiece and the speaker.
Parameters
|
Parameter |
Type |
Description |
|
focusChange |
int |
The type of the focus state. The value is the same as the focus type defined in `android.media.AudioManager`. |
onAudioRouteChanged
This callback is invoked when the audio routing changes (Android and iOS only).
public void onAudioRouteChanged(AliRtcEngine.AliRtcAudioRouteType routing);This callback notifies you of changes in the device's audio output path, such as when headphones are plugged in or the output is switched 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
This callback is invoked when a remote user subscribes to the Data Channel.
public void onRemoteUserSubscribedDataChannel(String uid);This callback is triggered when a remote user subscribes to the Data Channel. It notifies you that a specific remote user is ready to receive custom messages. At this point, you can safely call sendDataChannelMsg to send data to that user. This callback is a crucial mechanism for ensuring reliable message delivery because it prevents packet loss or failures that would otherwise occur if you send messages before the target user subscribes to the Data Channel.
This callback is triggered only in AI real-time interaction scenarios.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the remote user. |
onDataChannelMessage
This callback is invoked when a custom message is received over the data channel.
public void onDataChannelMessage(String uid, AliRtcEngine.AliRtcDataChannelMsg msg);The ARTC SDK lets you send and receive custom real-time messages along with audio and video data. This callback is used to receive custom messages from the data channel. For more information, see Sending and Receiving Custom Messages.
In interactive scenarios, streamers can send and receive messages, while viewers can only receive messages.
This feature is disabled by default. To enable it, you can call
setParameterto set{"data":{"enablePubDataChannel":true,"enableSubDataChannel":true}}after you create the DPI engine.The data channel feature requires that the sender has an active audio or video stream. Ensure that your scenario has active audio or video streams.
Triggering time
After a sender calls sendDataChannelMsg to send a custom message, this callback is triggered on the receiver's end if the data channel feature is enabled.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The sender's user ID. |
|
msg |
AliRtcEngine.AliRtcDataChannelMsg |
The received custom message. |
onAudioVolume
The volume of the subscribed audio, the voice status, and the UID.
public void onAudioVolume(List<AliRtcEngine.AliRtcAudioVolume> speakers, int totalVolume);This callback is disabled by default. You can enable it 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, whenever users are streaming in the channel, the SDK triggers this callback after you join the channel, 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>. The callback returns volume information for local and remote speakers.
Parameters
|
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 volume after audio mixing. Valid values: 0 to 255. In a callback to a local user, totalVolume is the volume after mixing the local user's audio. In a callback to a remote user, totalVolume is the volume after mixing audio from all speakers. |
onActiveSpeaker
You can subscribe to the current speaker.
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 remote users and identifies the one with the highest audio volume. The SDK counts how many times each remote user is identified as having the highest volume. Within the current time period, the remote user with the highest cumulative count is considered the most active user.
Triggering conditions
This callback is triggered when the channel contains two or more users and at least one remote user is active. The SDK reports the UID of the most active remote user.
If the most active remote user does not change, the SDK does not trigger the
onActiveSpeakercallback again.If the most active remote user changes, the SDK triggers this callback and reports the UID of the new most active remote user.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
The ID of the user who is speaking. A value of 0 indicates the local user. This parameter returns the ID of the user with the highest volume over the current time segment, not the ID of the user with the highest instantaneous volume. |
OnTestAudioVolume
Pre-call detection and volume information callback.
public void OnTestAudioVolume(int volume);This callback reports the volume of the audio capture device during a pre-call test, enabling you to verify that the local audio capture device is functioning correctly. It is triggered when you call startAudioCaptureTest.
Parameters
|
Parameter |
Type |
Description |
|
Volume |
int |
Volume value. |
onCapturedAudioFrame
The callback that is invoked when raw captured audio data is available.
boolean onCapturedAudioFrame(AliRtcAudioFrame frame);This callback provides the raw audio data captured by the current device. It is disabled by default. To receive this audio data:
You can enable this callback by calling enableAudioFrameObserver(true, audioSource, config). You must specify the audioSource parameter. The config parameter specifies the sample rate, number of sound channels, and read/write mode for the audio data.
Call registerAudioFrameObserver to register an audio data receiver object.
You can set the sample rate, number of sound channels, and read/write mode for this callback.
Limitations
Do not perform any time-consuming operations in this callback function because it may cause audio anomalies.
Parameters
|
Parameter |
Type |
Note |
|
frame |
Audio data. |
Return description
true: Success.
false: Failure.
onProcessCapturedAudioFrame
The callback that is invoked when audio data becomes available after 3A processing.
boolean onProcessCapturedAudioFrame(AliRtcAudioFrame frame);This callback retrieves audio data after 3A processing. It is disabled by default. To retrieve this audio data:
You can enable this callback by calling enableAudioFrameObserver(true, audioSource, config) and specifying the
audioSourceparameter. You can also use theconfigparameter to set 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.
You can use this method to set the sample rate, number of sound channels, and read/write mode.
Call restrictions
Do not perform any time-consuming operations in this callback function, because it may cause audio anomalies.
You can call this method before or after joining a channel.
|
Parameter |
Type |
Note |
|
frame |
Audio data. |
Return description
True indicates success.
false. Failed.
onPublishAudioFrame
Audio stream ingestion callback
boolean onPublishAudioFrame(AliRtcAudioFrame frame);This callback obtains audio data for stream ingest. It is disabled by default. To obtain this audio data:
You can enable this callback using the `audioSource` in enableAudioFrameObserver(true, audioSource, config). Additionally, the `config` parameter lets you set the sample rate and the number of sound channels for obtaining audio data, the read/write mode, and so on.
Call registerAudioFrameObserver to register an audio data receiver object.
This method lets you set the sample rate and the number of sound channels, but the mode can only be set to read-only.
Limitations
Do not perform any time-consuming operations in this callback function because doing so may cause audio issues.
Parameters
|
Parameter |
Type |
Note |
|
Frame |
Audio data. |
Return description
true: The operation succeeded.
false: Failed.
onPlaybackAudioFrame
The callback invoked when audio data is ready for playback.
boolean onPlaybackAudioFrame(AliRtcAudioFrame frame);This callback retrieves audio data for playback. It is disabled by default. To retrieve this audio data:
To enable the current callback, set the
audioSourceparameter when calling enableAudioFrameObserver(true, audioSource, config). You can also use theconfigparameter to set the sample rate, the number of sound channels, and the read/write mode for the audio data you obtain.Call registerAudioFrameObserver to register an audio data receiver object.
This method supports setting the sample rate, number of sound channels, and read/write mode.
Limitations
You must not perform time-consuming operations in this callback function because doing so may cause audio anomalies.
Parameters
|
Parameter |
Type |
Note |
|
frame |
AliRtcAudioFrame |
Audio data. |
Return description
true: The operation succeeded.
False indicates failure.
onRemoteUserAudioFrame
The callback that is invoked when audio data from a remote user is available for stream pulling.
boolean onRemoteUserAudioFrame(String uid, AliRtcAudioFrame frame);This callback retrieves the remote audio data for the specified user during stream pulling. It is disabled by default. To retrieve this audio data:
You can use the
audioSourceparameter in enableAudioFrameObserver(true, audioSource, config) to enable the current callback. You can also use theconfigparameter to specify properties for the audio data to be retrieved, such as the sample rate, the number of sound channels, and the read/write mode.You can call registerAudioFrameObserver to register an audio frame observer.
This method does not support setting the sample rate or number of sound channels, but it can set the read/write mode.
Limitations
To avoid audio anomalies, do not perform time-consuming operations in this callback function.
Parameter Description
|
Parameter |
Type |
Note |
|
uid |
String |
User ID. |
|
Frame |
Audio data. |
Return Description
true: The operation succeeded.
false: Indicates failure.
OnDestroyCompletion
The callback that the SDK invokes when engine destruction completes.
void OnDestroyCompletion();This callback indicates that the SDK engine instance has been destroyed and you can create a new instance.
Triggering time
This callback is triggered after you call destroy[2/2] and the DPI engine is destroyed.
onTextureCreate
This callback is invoked when the OpenGL context is created.
void onTextureCreate(long context);This callback is triggered when the SDK internally creates the OpenGL context.
Triggering conditions
This callback is triggered when the SDK internally creates the OpenGL context. You can use this callback to initialize relevant resources.
Parameters
|
Parameter |
Type |
Note |
|
Context |
long |
OpenGL context. |
onTextureUpdate
The callback that is invoked when the OpenGL texture is updated.
int onTextureUpdate(int textureId, int width, int height, AliRtcVideoSample videoSample);Triggering conditions
This callback is triggered after each video frame is uploaded to the OpenGL texture. When you register an external OpenGL texture data observer, you can process the texture in this callback and return the processed texture ID.
Parameters
|
Parameter |
Type |
Note |
|
textureId |
int |
OpenGL context. |
|
width |
int |
Video width. |
|
Height |
int |
The height of the video. |
|
videoSample |
Video frame data. |
Return description
Returns the new texture ID or the original texture ID. If the returned value is less than zero, the texture ID is considered unchanged.
onTextureDestroy
void onTextureDestroy();Triggering condition
This callback is triggered when the SDK internally destroys the OpenGL context. You should use this callback to clean up the relevant resources.
onLocalVideoSample
The callback that is invoked when locally captured video data becomes available.
public boolean onLocalVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);This callback retrieves raw video frames, such as YUV data, captured by the local camera. You can use this callback to implement custom video processing logic, such as adding filters, watermarks, or transcoding. To send the processed video frames to the SDK for subsequent encoding or rendering, return true.
Triggering Time
After registering a video data observer by calling <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="22a5a6bd53c77">registerVideoSampleObserver</a>, the SDK captures the corresponding video frames.
Parameters
|
Parameter |
Type |
Description |
|
sourceType |
Video source type. | |
|
videoSample |
Video data. |
Response description
true: Writes the data back to the SDK. (This is the default behavior. Writing back is required if you modify AliRtcVideoSample.data.)
false: The data is not written back to the SDK. This option is used when you need to directly manipulate AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, or AliRtcVideoSample.dataFrameV.
onPreEncodeVideoSample
Callback for subscribed local pre-encoding video data.
public boolean onPreEncodeVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoRawData);This callback retrieves raw local video data, such as data in the YUV format, before the SDK encodes the video frames. This lets you implement custom processing logic, such as adding watermarks, adjusting colors, or transcoding, and then decide whether to return the processed data to the SDK for encoding.
Parameters
|
Parameter |
Type |
Description |
|
sourceType |
Video stream type | |
|
videoRawData |
Raw video data |
Return Description
true: Data must be written back to the SDK when you operate on AliRtcVideoSample.data. This is the default setting.
false: Does not write data back to the SDK. (Use this option if you want to directly manipulate AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV.)
onRemoteVideoSample
Callback for subscribed remote video data.
public boolean onRemoteVideoSample(String callId,AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);This callback receives subscribed remote video data. It obtains raw video frame data (such as YUV format) from remote users. Developers can use this callback to implement custom processing logic (such as adding filters, watermarks, or transcoding) and determine 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 |
Video raw data |
Return description
true: The data is written back to the SDK. This is the default setting and is required when you operate on AliRtcVideoSample.data.
If `false`, the data does not need to be written back to the SDK. (This is used when directly operating on AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, or AliRtcVideoSample.dataFrameV.)
onGetVideoFormatPreference
Video output format
public AliRtcVideoFormat onGetVideoFormatPreference();Response description
The desired video output format.
onGetObservedFramePosition
Video data output content
public int onGetObservedFramePosition();This callback obtains the video data output content or type. Developers can use this callback to obtain the processing stage of SDK output video frames, such as after capture, before encoding, or after stream pulling.
Return Description
The expected video output content is an enumeration value of AliRtcVideoObserPosition, indicating captured data, stream-pulled data, and pre-encoding data.
onPublishLiveStreamStateChanged
This callback is invoked when the status of the relayed live stream changes.
public void onPublishLiveStreamStateChanged(String streamUrl, AliRtcLiveTranscodingState state, AliEngineLiveTranscodingErrorCode errorCode);Parameters
|
Parameter |
Type |
Description |
|
streamUrl |
String |
The ingest URL. |
|
state |
The status of bypass live streaming. | |
|
errorCode |
The error code. |
onPublishTaskStateChanged
Invoked when the relayed task's status changes.
public void onPublishTaskStateChanged(String streamUrl, AliRtcTrascodingPublishTaskStatus state);Parameters
|
Parameter |
Type |
Description |
|
streamUrl |
String |
The ingest URL. |
|
state |
The status of the relayed live streaming task. |
onNetworkQualityChanged
The callback that is invoked when the network quality changes.
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 upstream and downstream network status. |
|
upQuality |
The upstream network status. | |
|
downQuality |
Downstream network health. |
onNetworkQualityProbeTest
The callback that is invoked approximately 3 seconds after network quality testing starts.
public void onNetworkQualityProbeTest(AliRtcNetworkQuality quality){}Parameters
|
Parameter |
Type |
Description |
|
quality |
Network quality. |
onNetworkQualityProbeTestResult
A callback that reports the results of the network quality test, invoked approximately 30 seconds after the test starts.
public void onNetworkQualityProbeTestResult(int code, AliRtcEngine.AlirtcNetworkQualityProbeResult result){}Parameters
|
Parameter |
Type |
Description |
|
code |
int |
The return value is 0 if the probe succeeds and -1 if it fails because poor network conditions caused the connection to drop. |
|
result |
Network quality. |
onSnapshotComplete
The callback that is invoked when a screenshot operation completes.
public void onSnapshotComplete(String userId, AliRtcVideoTrack trackType, Bitmap bitmap, boolean success)This callback provides the screenshot result and details.
Parameters
|
Parameter |
Type |
Description |
|
userId |
String |
User ID. |
|
trackType |
The type of the video stream for screenshots. | |
|
bitmap |
Bitmap |
Screenshot data. |
|
Success |
boolean |
Indicates whether the screenshot was successful. |
onScreenSharePublishStateChanged
Callback for changes to the screen sharing stream ingest.
public void onScreenSharePublishStateChanged(AliRtcEngine.AliRtcPublishState oldState , AliRtcEngine.AliRtcPublishState newState, int elapseSinceLastState, String channel)This callback provides notifications for changes in screen sharing stream ingest status and is triggered when the status changes.
Parameter description
|
Parameter |
Type |
Description |
|
oldState |
AliRtcEngine.AliRtcPublishState |
The previous state before the stream ingest status changed. |
|
newState |
AliRtcEngine.AliRtcPublishState |
The new stream ingest status after the change. |
|
elapseSinceLastState |
int |
Time interval for status changes (ms). |
|
channel |
String |
The name of the current channel. |
onScreenShareSubscribeStateChanged
The callback that is invoked when the subscription status of a screen-sharing stream changes.
public void onScreenShareSubscribeStateChanged(String uid,
AliRtcEngine.AliRtcSubscribeState oldState,
AliRtcEngine.AliRtcSubscribeState newState,
int elapseSinceLastState, String channel);This callback is triggered when the current user's subscription status to a remote user's screen-sharing stream changes.
Parameters
|
Parameter |
Type |
Description |
|
uid |
String |
Remote User ID. |
|
oldState |
AliRtcEngine.AliRtcSubscribeState |
Previous subscription status. |
|
newState |
AliRtcEngine.AliRtcSubscribeState |
The current subscription status. |
|
elapseSinceLastState |
int |
State change interval (milliseconds). |
|
channel |
String |
Current channel. |
onOccurError
Fault notifications.
public void onOccurError(int error, String message);The ARTC SDK's global error notification callback notifies the application layer when a critical error occurs in the SDK's internal engine. Developers can use this callback to obtain the error code and error message for exception handling, logging, or user notification.
Response description
|
Parameter |
Type |
Description |
|
Error |
int |
Error type. For more information, see the error code list. |
|
message |
String |
Error message. |
OnLocalAudioStateChanged
This callback is invoked when the state of the local audio device changes.
public void OnLocalAudioStateChanged(int state);The callback is triggered when the state of the local audio capture device changes, such as when you call startAudioCapture to start audio capture or stopAudioCapture to stop audio capture.
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
Retrieves custom parameters.
public abstract String getParameter(String param);Parameters
|
Parameter |
Type |
Description |
|
param |
String |
Custom parameter. |
registerAudioVolumeObserver
Registers an object that is used to export volume data.
public abstract void registerAudioVolumeObserver(AliRtcAudioVolumeObserver observer);This method registers an object for exporting volume data. To unregister, call unRegisterAudioVolumeObserver.
When to call
To obtain volume information, 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 call this API to register the object that receives the relevant data.When you call
<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ae07dc986abf3" id="29e92857a5iv8">startAudioCaptureTest</a>before joining a meeting for pre-call audio device detection, you can call this API 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.
Parameters
|
Parameter |
Type |
Description |
|
observer |
Object that accepts audio volume data. |
unRegisterAudioVolumeObserver
Deregisters the object that exports volume data.
public abstract void unRegisterAudioVolumeObserver();This method corresponds to registerAudioVolumeObserver and removes the registered object that exports volume data.
When to call
You can call this method to unregister an audio volume observer if you previously registered one using registerAudioVolumeObserver.
enableAudioFrameObserver
You can set the audio callback parameters.
public abstract int enableAudioFrameObserver(boolean enable, AliRtcAudioSource audioSource, AliRtcAudioFrameObserverConfig config);This method enables or disables audio data callbacks for specified types, allowing developers to obtain various raw and encoded audio data. It is disabled by default. To enable it, you can call this method.
When calling this API to enable the audio data callback for the corresponding AliRtcAudioSource, you must use the registerAudioFrameObserver method to pass the object to receive the audio data.
When to call
You can call this method to enable the retrieval of audio data when you need it.
Parameters
|
Parameters |
Type |
Description |
|
enable |
boolean |
Whether to allow audio data callbacks. |
|
audioSource |
Callback data source types include after capture (0), after 3A (1), stream ingest (2), playback (3), after stream ingest and playback mixing (4), and pulled audio data (5). Note
| |
|
config |
Audio callback parameters, such as sample rate, number of sound channels, and callback read-write mode (read-only, write-only, or read-write). If you set these parameters to null, the default values are 48000 Hz, 1 channel, and read-only. |
Return Description
0: The method call succeeded.
<0: The method call failed.
registerAudioFrameObserver
You can register an audio data callback.
public abstract void registerAudioFrameObserver(AliRtcAudioFrameObserver observer);This method registers an object to receive audio callback data.
Invocation time
To receive audio data through the onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, and onRemoteUserAudioFrame callbacks, you must call this method to provide an audio data receiver object. To unregister the receiver, call this method again and pass null.
Call Limits
The observer cannot retrieve data unless you call enableAudioFrameObserver to enable the callback for a specific AliRtcAudioSource.
Parameter description
|
Parameter |
Type |
Description |
|
observer |
The audio data callback receiver object instance. If null is passed, it unregisters. |
registerVideoSampleObserver
Registers an object to export video data.
public abstract void registerVideoSampleObserver(AliVideoObserver observer);This method registers an object for exporting video data. You can unregister the object by calling the unRegisterVideoSampleObserver method.
When to call
To obtain raw video data (such as YUV or RGBA format), you can call this method to register a video data observer and obtain video data at various stages. AliRtcVideoObserver is the video data observer class.
Related callbacks
After successfully registering a video data output observer, the SDK triggers the callbacks you implemented in the AliRtcVideoObserver interface for each captured video frame. You can implement the corresponding callbacks as needed:
onLocalVideoSample: Callback for locally captured video data.
onRemoteVideoSample: Callback for remote video data.
onPreEncodeVideoSample: Callback for video data before local encoding.
Parameters
|
Parameter |
Type |
Description |
|
observer |
The output object for video data. |
Return Description
The AliVideoObserver callback returns the output data.
unRegisterVideoSampleObserver
Deregisters an object that is used to export 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 unregister the video data output object.
registerLocalVideoTextureObserver
Registers an object that exports the OpenGL texture data from the local camera track.
public abstract void registerLocalVideoTextureObserver(AliTextureObserver observer);To retrieve 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> API to register the corresponding callback. To retrieve internal texture data, call this API. To unregister the texture observer, call the unRegisterLocalVideoTextureObserver API.
This method applies only to video from a local camera stream.
Related callbacks
After you successfully register a local camera stream video OpenGL texture data observer, 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 OpenGL context.
onTextureUpdate: This callback is triggered after the video data for each frame is uploaded to an OpenGL texture. If you register an external OpenGL texture data observer, you can process the texture in this callback and return the processed texture ID. The return value of this callback must be a valid texture ID. If you do not perform any processing, you must return the original
textureIdparameter.onTextureDestroy: This callback is triggered when the internal OpenGL context of the SDK is destroyed.
Parameters
|
Parameter |
Type |
Description |
|
observer |
OpenGL texture data observer. |
Return description
Output data is returned in the AliVideoObserver callback.
unRegisterLocalVideoTextureObserver
Unregisters the observer for OpenGL texture data from a local camera track.
public abstract void unRegisterLocalVideoTextureObserver();This method unregisters the observer registered by registerLocalVideoTextureObserver.
snapshotVideo
Video snapshot feature.
public abstract int snapshotVideo(String userId, AliRtcVideoTrack trackType);Call this method to capture a screenshot of a video stream from a specified user.
Limitations
This method is asynchronous. A return value of 0 indicates that the call is successful, but the screenshot has not yet been captured.
Related callbacks
After you successfully call this method, listen to the onSnapshotComplete callback to obtain the success status and snapshot details.
Parameters
|
Parameter |
Type |
Description |
|
user ID |
String |
The user ID. If userId is null or an empty string (""), a screenshot is taken of the local user. |
|
trackType |
The type of video stream for the snapshot. The following values are supported:
|
Return description
0: indicates only that the method call succeeded. Whether the screenshot was successful is provided by the onSnapshotComplete callback.
Non-zero: the call failed and returns an error code.
setLogDirPath
You can set the save path for the SDK log file.
public static int setLogDirPath(String logDirPath);Parameters
|
Parameter |
Type |
Description |
|
logDirPath |
String |
The absolute path for storing log files. The default path is the app directory. |
Return Description
A value of 0 indicates that the call is successful. Any other value indicates failure. Note: To call this method, it must be set before calling any other SDK methods to avoid log loss. The app must ensure that the specified path exists and is writable.
setLogLevel
Sets the log level.
public static void setLogLevel(AliRtcLogLevel logLevel);Parameters
|
Parameter |
Type |
Description |
|
logLevel |
The log level. |
setDeviceOrientationMode
You can set the device orientation.
public abstract void setDeviceOrientationMode(AliRtcOrientationMode mode);This method sets the device orientation mode, which affects how video is displayed.
Limitations
This method is only available on Android and iOS.
Parameters
|
Parameter |
Type |
Description |
|
mode |
AliRtcOrientationMode |
Device direction. |
Return description
None.
requestAudioFocus
Sets the local playback volume of the sound effect.
public abstract int requestAudioFocus();When to call
The SDK automatically requests audio focus when it starts, so you typically do not need to request it manually. However, if you have called abandonAudioFocus, you can call this API to regain audio focus.
Limitations
Android only.
Parameters
None.
Return description
0: Indicates failure.
1: Indicates success.
abandonAudioFocus
Release audio focus.
public abstract int abandonAudioFocus();When to Call
The SDK automatically calls this interface to release audio focus during its destruction. However, in some scenarios, you might need to explicitly release audio focus by calling this interface. After audio focus is released, some devices might produce no sound or a lower volume. To restore audio focus, call requestAudioFocus.
Invocation Limits
Android only.
Return Description
0: Failure.
1: Success.
getNetworkTime
Obtain the current network time.
public abstract long getNetworkTime();This method returns the current network time in milliseconds, which is the current timestamp adjusted by NTP calibration and the time offset.
Invocation Timing
When synchronizing multi-device behavior, you must obtain synchronized network time as a baseline to calibrate the current time.
Return Description
The current time, in milliseconds, according to Network Time Protocol (NTP).
sendDataChannelMsg
You can send a custom message over the data channel.
public abstract int sendDataChannelMsg(AliRtcDataChannelMsg Msg);The ARTC SDK lets you send and receive custom messages in real time along with audio and video data. For example, you can call this interface to send real-time control instructions, state synchronization data, or other business messages. For more information, see Custom message sending and receiving.
The custom message channel is disabled by default. To use this feature, call the setParameter method to enable the custom message channel by setting
{"data":{"enablePubDataChannel":true,"enableSubDataChannel":true}}. You can enable it before or after joining a channel.Messages can contain any data, such as text.
ARTC DataChannel functionality requires the ingesting party to ingest audio or video streams. Ensure that your scenario includes active audio or video streams.
Related callbacks
After a sender successfully opens a custom message channel, you can call this API to send custom messages. The receiver obtains these messages by listening for the onDataChannelMessage callback.
Limitations
Streamers can send and receive messages, while viewers can only receive them.
Call setParameter to enable the custom message channel.
Data sending has the following limits:
Maximum bitrate: 30 KB/s.
Maximum packet rate: 60 packets per second, with a maximum packet size of 1 KB.
Parameters
|
Parameter |
Type |
Description |
|
Msg |
The content of the message. |
Return Description
0: The call succeeded.
A non-zero value: The call failed and returns an error code.
startScreenShare
This API will be deprecated soon. We recommend that you use the new startScreenShare API.
You can start sharing the screen and audio stream.
public abstract int startScreenShare(Intent intent);Parameters
|
Name |
Description |
|
intent |
You can provide an external Activity to initiate screen sharing. However, we recommend that you pass null instead. |
return value
A value of 0 indicates success.
Any other value indicates failure.
startScreenShare
This API is deprecated. We recommend that you use the new startScreenShare API.
This method starts screen sharing.
public abstract int startScreenShare();Return value
0: Success.
Other values: Failure.
startScreenShare
You can start sharing the screen video stream.
public abstract int startScreenShare(Intent intent, AliRtcScreenShareMode screenShareMode);Parameters
|
Name |
Description |
|
intent |
An Activity created externally to start screen sharing. If no external Activity is created, pass null. Passing null is recommended. |
|
screenShareMode |
The screen-sharing mode. For more information, see AliRtcScreenShareMode. |
Return value
0: Success.
Other values: Failure.
stopScreenShare
Stops the screen sharing stream, which includes the audio stream.
public abstract int stopScreenShare();Return value
A value of 0 indicates success.
Any other value indicates failure.
setAudioShareVolume
You can set the audio stream volume for stream ingest.
public abstract int setAudioShareVolume(int volume);Parameters
|
Name |
Description |
|
volume |
The volume. Valid values: 0 to 100. Default value: 50. |
Return value
0: Success.
Other values: Failure.
isScreenSharePublished
Check if screen sharing stream ingest is in progress.
public abstract boolean isScreenSharePublished();Return value
true: A screen-sharing stream is being ingested.
false: No screen-sharing streams are 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 streams, such as resolution, frame rate, bitrate, and video orientation.
All parameters have corresponding range limits. If a parameter is set outside its valid range, the SDK automatically adjusts it. Therefore, the actual configuration may differ from your settings.
When to call
You can call this method before or after joining a channel. If you only need to set screen-sharing stream video encoding properties once per session, we recommend calling it before joining.
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, primarily affecting the transmission destination of log reporting and instrumentation data :
When set to the Chinese mainland environment, logs and instrumentation data are reported to data centers in the Chinese mainland.
When set to the overseas environment, related data is routed to overseas data centers (such as Singapore).
When to call
We recommend calling this method early in the application initialization, such as in the onCreate() method of the Application.
Call Limits
-
This is a global setting. Call it only once.
-
Multiple calls overwrite the previous environment configuration. This may affect established connections or session states. Do not switch the setting dynamically while it is running.
Call example
AlivcEnv.GlobalEnv env = ENV_DEFAULT; // If you need an environment outside China, use ENV_SEA.
AlivcBase.getEnvironmentManager().setGlobalEnvironment(env);Parameters
|
Parameter |
Type |
Description |
|
env |
|
Specify the global environment. Supported enumeration values include the following: |
Return value
Returns a result code of type int:
-
0: Indicates success. -
Any value other than
0: Indicates failure.