AliRtcEngine interface

Updated at:

This topic describes the interfaces of the ApsaraVideo Real-time Communication SDK for Android.

Contents

Basic interfaces

API

Description

getInstance[1/2]

Creates an AliRtcEngine instance (singleton pattern).

getInstance[2/2]

Creates an AliRtcEngine instance (singleton pattern).

destroy[1/2]

Destroys the AliRtcEngine object.

destroy[2/2]

Destroys the AliRtcEngine object.

setH5CompatibleMode

Sets the H5 compatible mode.

getH5CompatibleMode

Checks whether the current mode is H5 compatible.

setRtcEngineEventListener

Sets the listener for local user behavior event callbacks.

setRtcEngineNotify

Sets the listener for remote user behavior notification events.

getSdkVersion

Queries the current SDK version.

Channel interfaces

API

Description

setChannelProfile

Sets the channel mode.

setAudioProfile

Sets the audio encoding mode and scenario mode.

isAudioOnly

Queries whether the current mode is audio-only.

setAudioOnlyMode

Sets the mode to audio-only or audio and video.

joinChannel[1/3]

Joins a channel.

joinChannel[2/3]

Joins a channel.

joinChannel[3/3]

Joins a channel.

leaveChannel

Leaves a channel.

isInCall

Checks whether the user is in a channel.

setClientRole

Sets the user role.

getCurrentClientRole

Gets the user role.

refreshAuthInfo[1/2]

Refreshes the authentication information.

refreshAuthInfo[2/2]

Refreshes the authentication information.

Publishing and subscription interfaces

API

Description

publishLocalAudioStream

Stops or resumes publishing the local video stream. Publishing is enabled by default.

isLocalAudioStreamPublished

Queries whether the audio stream is being published.

setDefaultSubscribeAllRemoteAudioStreams

Sets whether to subscribe to remote audio streams by default. By default, all remote audio streams are subscribed. Call this method before joining a channel.

subscribeRemoteAudioStream

Stops or resumes pulling the audio stream of a specific remote user.

subscribeAllRemoteAudioStreams

Stops or resumes subscribing to all remote audio streams.

publishLocalVideoStream

Specifies whether to publish the local video stream. The SDK publishes the stream by default.

isLocalVideoStreamPublished

Queries whether the video stream is being published.

setDefaultSubscribeAllRemoteVideoStreams

Sets whether to subscribe to remote video streams by default. By default, all remote video streams are subscribed. Call this method before joining a channel.

subscribeRemoteVideoStream

Stops or resumes subscribing to a specific remote video stream.

subscribeAllRemoteVideoStreams

Stops or resumes subscribing to all remote video streams.

subscribeRemoteMediaStream[1/2]

Stops or resumes the media stream of a specific remote user. Use this method when both audio and video exist and need to be controlled.

subscribeRemoteMediaStream[2/2]

Stops or resumes the media stream of a specific remote user. Use this method when both audio and video exist and need to be controlled.

subscribeRemoteDestChannelStream

Stops or resumes the media stream of a specific remote user across channels.

subscribeRemoteDestChannelAllStream

Stops or resumes subscribing to the streams of all users across channels.

setRemoteAudioVolume

Adjusts the playback volume of a pulled stream.

Audio device management interfaces

API

Description

muteLocalMic

Sets whether to stop publishing local audio.

muteRemoteAudioPlaying

Sets whether to stop playing remote audio streams.

muteAllRemoteAudioPlaying

Stops or resumes all remote audio playback.

startAudioCapture[1/2]

Enables audio collection.

startAudioCapture[2/2]

Enables audio collection.

stopAudioCapture

Disables audio collection.

setDefaultAudioRoutetoSpeakerphone

Sets the default audio output device.

enableSpeakerphone

Sets the audio output to the earpiece or speaker.

isSpeakerOn

Gets whether the current audio output is the earpiece or speaker.

enableAudioVolumeIndication

Enables the volume detection feature.

enableEarBack

Enables in-ear monitoring.

setEarBackVolume

Sets the in-ear monitoring volume.

startAudioPlayer

Turns on the audio playback device.

stopAudioPlayer

Turns off the audio playback device.

setPlayoutVolume

Sets the local playback volume.

setRecordingVolume

Sets the recording volume.

playAudioFileTest

Plays an audio file.

stopAudioFileTest

Stops playing the audio file.

startAudioCaptureTest

Enables audio collection device detection before a call.

stopAudioCaptureTest

Disables audio collection detection.

Audio voice changing and reverberation

API

Description

setAudioEffectVoiceChangerMode

Sets the voice changer effect mode.

setAudioEffectPitchValue

Sets the pitch shifting parameter.

setAudioEffectReverbMode

Sets the reverberation effect mode.

setAudioEffectReverbParamType

Sets the reverberation effect type and specific parameters.

setAudioEffectBeautifyMode

Sets the preset voice beautification effect mode.

setAudioEffectEqualizationParam

Sets the audio equalizer (EQ) parameters to adjust the gain of a specified frequency band.

Custom audio input

API

Description

addExternalAudioStream

Adds an external audio stream.

pushExternalAudioStreamRawData

Inputs external audio stream data.

setExternalAudioStreamPublishVolume

Sets the ingest volume.

getExternalAudioStreamPublishVolume

Gets the ingest volume.

setExternalAudioStreamPlayoutVolume

Sets the external audio stream playback volume.

getExternalAudioStreamPlayoutVolume

Gets the external audio stream playback volume.

removeExternalAudioStream

Deletes an external audio stream.

Music accompaniment

API

Description

getAudioFileInfo

Gets audio file information.

startAudioAccompany

Starts accompaniment mixing.

stopAudioAccompany

Stops accompaniment mixing.

setAudioAccompanyVolume

Sets the accompaniment volume, including local playback volume and ingest volume.

setAudioAccompanyPublishVolume

Sets the accompaniment ingest volume.

getAudioAccompanyPublishVolume

Gets the accompaniment ingest volume.

setAudioAccompanyPlayoutVolume

Sets the accompaniment local playback volume.

getAudioAccompanyPlayoutVolume

Gets the accompaniment local playback volume.

pauseAudioAccompany

Pauses accompaniment mixing.

resumeAudioAccompany

Resumes accompaniment mixing.

getAudioAccompanyDuration

Gets the duration of the accompaniment file in milliseconds.

getAudioAccompanyCurrentPosition

Gets the playback progress of the accompaniment file in milliseconds.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

Sound effect files

API

Description

preloadAudioEffect

Preloads a sound effect file.

unloadAudioEffect

Deletes a preloaded sound effect file.

playAudioEffect

Starts playing a sound effect.

stopAudioEffect

Stops playing a sound effect.

stopAllAudioEffects

Stops playing all sound effects.

pauseAudioEffect

Pauses a sound effect.

pauseAllAudioEffects

Pauses all sound effects.

resumeAudioEffect

Resumes a specified sound effect file.

resumeAllAudioEffects

Resumes all sound effect files.

setAudioEffectPublishVolume

Sets the sound effect ingest mixing volume.

getAudioEffectPublishVolume

Gets the sound effect ingest mixing volume.

setAllAudioEffectsPublishVolume

Sets the ingest mixing volume for all sound effects.

setAudioEffectPlayoutVolume

Sets the local playback volume for a sound effect.

getAudioEffectPlayoutVolume

Gets the local playback volume for a sound effect.

setAllAudioEffectsPlayoutVolume

Sets the local playback volume for all sound effects.

Record audio and video files

API

Description

startRecord

Records audio and video files (AAC, WAV, MP4).

stopRecord

Stops recording audio and video files.

Video device management interfaces

API

Description

createRenderSurfaceView

Creates a SurfaceView rendering view.

setLocalViewConfig

Sets the rendering window and drawing parameters for the local preview.

setRemoteViewConfig

Sets the rendering window and drawing parameters for a remote video.

setCameraCapturerConfiguration

Sets the camera capture preferences.

enableLocalVideo

Disables or re-enables local video collection.

muteLocalCamera

Sets whether to stop publishing the local video stream.

isCameraOn

Checks whether the camera is on.

setVideoEncoderConfiguration

Sets the video encoding properties.

setVideoDecoderConfiguration

Sets the video decoding properties.

switchCamera

Switches between the front and rear cameras. The front camera is used by default.

getCurrentCameraDirection

Gets the current camera direction.

startPreview

Starts the local preview.

stopPreview

Stops the local preview.

setCameraZoom

Sets the camera zoom ratio.

GetCameraMaxZoomFactor

Gets the maximum zoom ratio supported by the camera.

GetCurrentZoom

Gets the current camera zoom ratio setting.

SetExposure

Sets the camera exposure.

GetCurrentExposure

Gets the camera exposure.

GetMinExposure

Gets the minimum exposure supported by the camera.

GetMaxExposure

Gets the maximum exposure supported by the camera.

setCameraFlash

Sets the camera flash on or off.

isCameraFocusPointSupported

Checks whether the current device supports manual focus.

setCameraFocusPoint

Sets the manual focus point for the camera.

isCameraExposurePointSupported

Checks whether setting the camera exposure point is supported.

setCameraExposurePoint

Sets the camera exposure point.

isCameraAutoFocusFaceModeSupported

Checks whether camera auto face focus is supported.

setCameraAutoFocusFaceModeEnabled

Sets camera face focus.

setVideoMirrorMode

Sets the video mirroring capability for preview and ingest.

setCapturePipelineScaleMode

Sets the video capture scaling time.

Configure video data callbacks

API

Description

registerVideoSampleObserver

Registers a video data output object.

unRegisterVideoSampleObserver

Unregisters a video data output object.

registerLocalVideoTextureObserver

Registers an OpenGL texture data observer for the local camera stream video.

unRegisterLocalVideoTextureObserver

Unregisters the OpenGL texture data observer for the local camera stream video.

snapshotVideo

Video snapshot feature.

Configure audio data callbacks

API

Description

registerAudioVolumeObserver

Registers a volume data output object.

unRegisterAudioVolumeObserver

Unregisters a volume data output object.

enableAudioFrameObserver

Sets audio callback parameters.

registerAudioFrameObserver

Registers an audio data callback.

Custom video input

API

Description

setExternalVideoSource

Enables an external video input source.

pushExternalVideoFrame

Inputs video data.

Desktop sharing interfaces

API

Description

startScreenShare

Starts publishing the screen sharing stream.

startScreenShare

Starts sharing the screen and audio stream.

Note

This interface will be deprecated.

startScreenShare

Starts screen sharing.

Note

This interface will be deprecated.

stopScreenShare

Stops publishing the screen sharing stream.

setAudioShareVolume

Sets the shared audio stream volume.

isScreenSharePublished

Queries whether screen sharing is set to be published.

setScreenShareEncoderConfiguration

Sets the video encoding properties for the screen stream.

Bypass live streaming interfaces

API

Description

startPublishLiveStream

Starts bypass live streaming.

updatePublishLiveStream

Updates bypass live streaming parameters.

stopPublishLiveStream

Stops bypass live streaming.

getPublishLiveStreamState

Gets the bypass live streaming status.

Network quality probe interfaces

API

Description

startNetworkQualityProbeTest

Starts a network quality probe.

stopNetworkQualityProbeTest

Stops a network quality probe.

SEI

API

Description

sendMediaExtensionMsg

Pushes an SEI stream.

sendMediaExtensionMsgEx

Pushes an SEI stream (extended).

Other interfaces

API

Description

setParameter

Sets custom parameters.

getParameter

Gets custom parameters.

setLogDirPath

Sets the save path for SDK log files.

setLogLevel

Sets the log level.

setDeviceOrientationMode

Sets the device orientation.

requestAudioFocus

Requests audio focus.

abandonAudioFocus

Abandons audio focus.

getNetworkTime

Gets the current network time.

sendDataChannelMsg

Sends a custom data channel message.

AliveEnc interface

API

Description

setGlobalEnvironment

Sets the global environment.

Callbacks

AliRtcEngineEventListener

API

Description

onConnectionStatusChange

Callback for network connection status changes. You need to handle this callback.

OnLocalDeviceException

Callback for local device exceptions. You need to handle this callback.

onJoinChannelResult

Callback for the result of joining a channel.

onLeaveChannelResult

Callback for the result of leaving a channel.

onAudioPublishStateChanged

Callback for audio publishing state changes.

onAudioSubscribeStateChanged

Callback for audio subscription state changes.

onVideoPublishStateChanged

Callback for video publishing state changes.

onVideoSubscribeStateChanged

Callback for camera stream subscription state changes.

onPublishLiveStreamStateChanged

Callback for bypass stream publishing state changes.

onPublishTaskStateChanged

Callback for bypass task state changes.

onNetworkQualityChanged

Callback for network quality changes.

onNetworkQualityProbeTest

Callback for a network quality probe. This callback is provided about 3 seconds after the probe starts.

onNetworkQualityProbeTestResult

Callback for the result of a network quality probe. This callback is provided about 30 seconds after the probe starts.

onSnapshotComplete

Callback interface for snapshot results.

onScreenSharePublishStateChanged

Callback for screen sharing publishing state changes.

onScreenShareSubscribeStateChanged

Callback for screen sharing stream subscription state changes.

onOccurError

Error notification.

OnLocalAudioStateChanged

Callback for local audio device status.

AliRtcEngineNotify

API

Description

onAuthInfoWillExpire

Notification that user authentication information is about to expire. Authentication expires 30 seconds after this callback is received. You need to handle this callback.

onAuthInfoExpired

The server returns that the information has expired when the user calls an interface that requires authentication.

onRemoteUserOffLineNotify

Notification that a remote user has gone offline.

onRemoteUserOnLineNotify

Notification that a remote user has come online.

onRemoteTrackAvailableNotify

Notification of remote stream publishing information.

onBye

Message indicating the user was kicked from the server or the channel has ended.

onUserAudioMuted

Notification that a remote user is muted.

onUserAudioInterruptedBegin

Notification that an audio device interruption has started.

onUserAudioInterruptedEnded

Notification that an audio device interruption has ended.

onUserVideoMuted

Notification that the remote user is sending black video frames.

onUserVideoEnabled

Notification that the remote user has disabled camera stream collection.

onUserWillResignActive

The remote user's application has moved to the background.

onUserWillBecomeActive

The remote user's application has returned to the foreground.

onAudioEffectFinished

Callback for when local sound effect playback finishes.

onAudioFileInfo

Callback for audio file information.

onMediaExtensionMsgReceived

Callback for receiving a media extension message.

onFirstRemoteVideoFrameDrawn

This message is triggered when the first video frame of a remote user is displayed.

onFirstLocalVideoFrameDrawn

This message is triggered when the first video frame is displayed in the preview.

onFirstVideoFrameReceived

Callback for receiving the first video frame from a remote user.

onFirstVideoPacketSent

Callback for the first video packet sent.

onFirstAudioPacketSent

Callback for the first audio packet sent.

onFirstVideoPacketReceived

Callback for the first video packet received.

onFirstAudioPacketReceived

Callback for the first audio packet received.

onFirstRemoteAudioDecoded

Callback for the first decoded remote audio frame.

onAudioAccompanyStateChanged

Callback for local accompaniment playback state.

onRemoteAudioAccompanyStarted

Callback for when a remote user's accompaniment starts playing.

onRemoteAudioAccompanyFinished

Callback for when a remote user's accompaniment finishes playing.

onAliRtcStats

Real-time data callback (triggered every 2 seconds).

onRtcLocalVideoStats

Data statistics for the published local video stream (triggered every 2 seconds).

onRtcRemoteVideoStats

Data statistics for the subscribed remote video stream (triggered every 2 seconds).

onRtcRemoteAudioStats

Data statistics for the subscribed remote audio stream (triggered every 2 seconds).

onRtcLocalAudioStats

Data statistics for the published local audio stream (triggered every 2 seconds).

onAudioFocusChange

Callback for audio focus changes (Android only).

onAudioRouteChanged

Callback for audio route changes (Android and iOS only).

onRemoteUserSubscribedDataChannel

Callback indicating that you can start sending data channel messages.

onDataChannelMessage

Callback for receiving custom data channel messages.

AliRtcAudioVolumeObserver

API

Description

onAudioVolume

Callback for user volume indication.

onActiveSpeaker

Voice activity detection. Callback when an active user is detected.

OnTestAudioVolume

Pre-call test. Callback for volume information.

AliRtcAudioFrameObserver

API

Description

onCapturedAudioFrame

Callback for raw audio collection data.

onProcessCapturedAudioFrame

Callback for audio data after 3A processing.

onPublishAudioFrame

Callback for published audio data.

onPlaybackAudioFrame

Callback for playback data.

onRemoteUserAudioFrame

Callback for remote pulled stream data.

AliRtcDestroyCompletionObserver

API

Description

OnDestroyCompletion

Callback for when the engine is destroyed.

AliRtcTextureObserver

API

Description

onTextureCreate

Callback for OpenGL context creation.

onTextureUpdate

Callback for OpenGL texture updates.

onTextureDestroy

Callback for OpenGL context destruction.

AliRtcVideoObserver

API

Description

onLocalVideoSample

Callback for subscribed local video collection data.

onPreEncodeVideoSample

Callback for subscribed local pre-encoding video data.

onRemoteVideoSample

Callback for subscribed remote video data.

onGetVideoFormatPreference

Video data output format.

onGetObservedFramePosition

Video data output content.

Interface details

getInstance[1/2]

Gets an AliRtcEngine instance (singleton pattern).

public static AliRtcEngineImpl getInstance(Context context);
Note
  • Both this method and getInstance[2/2] can create an AliRtcEngine instance. The difference is that getInstance[2/2] supports applying additional configurations during instance creation.

When to call

Call this method to create an AliRtcEngine instance before you call other ARTC SDK APIs.

Limits

The SDK supports creating only one AliRtcEngine instance for each application.

Parameters

Parameter

Type

Description

context

Context

The context of the Android Activity.

Return value

An `AliRtcEngineImpl` instance.

getInstance[2/2]

Gets an AliRtcEngine instance (singleton pattern).

public static AliRtcEngineImpl getInstance(Context context, String extras);
Note
  • 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 be used to create an AliRtcEngine instance. The difference is that this method allows you to specify more configurations when you create the instance.

When to call

Call this method to create an AliRtcEngine instance before you call other ARTC SDK APIs.

Limits

The SDK supports creating only one AliRtcEngine instance for each application.

Parameters

Parameter

Type

Description

context

Context

The context of the Android Activity.

extras

String

Used to receive grayscale parameters from the customer to configure special SDK features through JSON Configurations. This can be an empty string.

Return value

Returns a singleton instance of the `AliRtcEngineImpl` class. The `AliRtcEngineImpl` class is a child class of the `AliRtcEngine` class.

destroy[1/2]

Destroys the AliRtcEngine object.

public abstract void destroy();

This method destroys the AliRtcEngine singleton object. After you call this method, all internal resources are released, and you can no longer use any other methods or callbacks of AliRtcEngine. To use the engine again, you must call getInstance again to create a new instance.

Note
  • This method and destroy[2/2] can both destroy the engine instance. The difference is that destroy[2/2] lets you pass a listener object for destruction completion.

  • To create another AliRtcEngine instance after destroying one, make sure this method has finished executing before you create the new instance.

When to call

After a real-time communication session ends and you no longer need the AliRtcEngine, call this method to release the instance and free up resources.

Limits

  • To avoid deadlocks, do not call this method in any SDK callbacks.

  • After you call this method, set the engine object to null. Example:

    mAliRtcEngine.destroy();
    mAliRtcEngine = null;

destroy[2/2]

Destroys the AliRtcEngine object.

public abstract void destroy(AliRtcDestroyCompletionObserver observer);

Destroys the AliRtcEngine singleton object. This method releases all internal resources. You can no longer use other AliRtcEngine methods or any callbacks. To use the engine again, you must call getInstance to create a new instance.

Note

This is an asynchronous method. It provides an observer to let developers know when the destroy operation is complete. You can create a new instance only after the OnDestroyCompletion callback is returned. The instance is not destroyed until the observer callback is triggered.

When to call

After a real-time communication session ends, call this method to release the instance.

Limits

To avoid deadlocks, do not call this method in any SDK callbacks.

Related callbacks

After the SDK engine object is destroyed, the OnDestroyCompletion callback is triggered, indicating that a new instance can be created.

Parameters

Parameter

Type

Description

observer

AliRtcDestroyCompletionObserver

A notification callback for when the engine is destroyed. You can listen to this callback to ensure resources are completely released.

setH5CompatibleMode

Sets whether to enable H5 compatibility.

public static int setH5CompatibleMode(int enable);

Parameters

Parameter

Type

Description

enable

int

Sets whether to enable H5 compatibility. Valid values:

  • 0 (default): H5 is not compatible.

  • 1: H5 is compatible.

Important

The current version does not support changing the H5 compatible mode after an AliRtcEngine instance is created. You must call this method before creating the instance.

getH5CompatibleMode

Checks whether the current mode is H5 compatible.

public static int getH5CompatibleMode();

Return value

  • 1: H5 is compatible.

  • 0: H5 is not compatible.

setRtcEngineEventListener

Sets the listener for local user behavior notification events.

public abstract void setRtcEngineEventListener(AliRtcEngineEventListener listener);

This method sets the listener for events related to the local user. These events include the results of joining or leaving a channel, user role changes, audio and video publishing state changes, audio and video subscription state changes, network quality changes and probe results, snapshot results, device status and exception notifications, and SDK error notifications. By implementing the callback methods of this class, you can handle the lifecycle and state changes related to the local user and RTC.

Note
  • By default, all interfaces have an empty implementation. You do not need to implement all callbacks. You can implement the corresponding event methods based on your business needs.

  • To implement callbacks for remote users, first-frame and first-packet events, sound effect and accompaniment playback status, and authentication information, implement the relevant callbacks of the AliRtcEngineNotify class and call the setRtcEngineNotify interface.

  • Do not perform time-consuming operations in the callback methods, such as calling the engine's own destroy method. This may cause unnecessary blocking and affect the SDK's operation.

When to call

Call this method before joining a channel.

Related callbacks

If an exception occurs during operation, the SDK first tries to use its internal retry mechanism to recover automatically. For errors that cannot be resolved internally, the SDK notifies your application through predefined callback interfaces. The following are key callbacks for issues that the SDK cannot handle and that require the application layer to listen for and respond to:

Reason for exception

Callback and parameters

Solution

Description

Authentication failed

The result in the onJoinChannelResult callback returns AliRtcErrJoinBadToken.

If this error occurs, the application needs to check if the token is correct.

When a user actively calls an API, if authentication fails, the system returns an authentication failure error message in the API's callback.

Network connection exception

The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed.

If this exception occurs, the application needs to rejoin the channel.

The SDK can automatically recover from a network disconnection for a certain period. However, if the disconnection time exceeds a preset threshold, a timeout is triggered, and the connection is lost. In this case, the application should check the network status and guide the user to rejoin the session.

Local device exception

onLocalDeviceException

If this exception occurs, the application needs to check if permissions and device hardware are normal.

The RTC service supports device detection and exception diagnosis. When a local device exception occurs, the RTC service notifies the customer through a callback. If the SDK cannot resolve the issue on its own, the application needs to intervene to check if the device is normal.

Parameters

Parameter

Type

Description

listener

AliRtcEngineEventListener

Sets the listener for local user behavior notification events.

setRtcEngineNotify

Sets the listener for remote user behavior notification events.

public abstract void setRtcEngineNotify(AliRtcEngineNotify listener);

This method sets the listener for events related to remote users. These events include notifications for remote users coming online or going offline, remote user audio and video publishing status, remote user resolution changes, sending and receiving status of first audio/video frames and packets for both remote and local users, local and remote sound effect and accompaniment playback status, mute status, local and remote audio/video stream statistics, SEI reception, custom message reception, and authentication information changes. By implementing the callback methods of this class, you can handle event information related to interaction with remote users.

Note
  • By default, all interfaces have an empty implementation. You do not need to implement all methods. You can implement the corresponding event methods based on your business needs.

  • Do not perform time-consuming operations in the callback methods, such as calling the engine's own destroy method. This may cause unnecessary blocking and affect the SDK's operation.

When to call

Call this method before joining a channel.

Related callbacks

If an exception occurs during operation, the SDK first tries to use its internal retry mechanism to recover automatically. For errors that cannot be resolved internally, the SDK notifies your application through predefined callback interfaces. The following are key callbacks for issues that the SDK cannot handle and that require the application layer to listen for and respond to:

Reason for exception

Callback and parameters

Solution

Description

Kicked offline

onBye

  • AliRtcOnByeUserReplaced: If this exception occurs, check if the user IDs are the same.

  • AliRtcOnByeBeKickedOut: If this exception occurs, it means the user was kicked by the business logic. The user needs to rejoin the channel.

  • AliRtcOnByeChannelTerminated: If this exception occurs, it means the channel was destroyed. The user needs to rejoin the channel.

The RTC service provides a feature for administrators to actively remove participants.

Authentication about to expire

onWillAuthInfoExpire

If this exception occurs, the application needs to get the latest authentication information and then call refreshAuthInfo to refresh it.

Authentication expiration errors occur in two situations: when the user calls an API or during program execution. Therefore, the error feedback is provided through an API callback or a separate error callback.

Authentication expired

onAuthInfoExpired

If this exception occurs, the application needs to rejoin the channel.

Authentication expiration errors occur in two situations: when the user calls an API or during program execution. Therefore, the error feedback is provided through an API callback or a separate error callback.

Parameters

Parameter

Type

Description

listener

AliRtcEngineNotify

Sets the listener for remote user behavior notification events to receive messages from the engine.

getSdkVersion

Queries the current SDK version.

public static String getSdkVersion();

Return value

The current SDK version number in string format, for example, "2.5.0.x".

setChannelProfile

Sets the channel mode.

public abstract int setChannelProfile(AliRTCSdkChannelProfile channelProfile);

This method sets the channel mode. It currently provides two scenarios: video call and interactive live streaming:

  • Video call mode: All users are streamers and can publish and subscribe to streams.

  • Interactive stream mode: You must call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="18edf3ea54po4">setClientRole</a> to set the user role. Users who ingest streams in the channel are assigned the streamer role (AliRTCSdkInteractive). If a user only needs to pull streams and does not ingest streams, they are assigned the viewer role (AliRTCSdkLive). This mode is recommended for RTC scenarios.

Note
  • We recommend that you use the interactive stream mode for all RTC scenarios. To do this, call this API and set the mode to AliRTCSdkInteractiveLive.

  • All users in the same channel must use the same channel mode.

When to call

Call this method only before you join a channel. You cannot reset the channel mode after you join a channel. You can reset the mode after you leave the channel.

Parameters

Parameter

Type

Description

channelProfile

AliRTCSdkChannelProfile

The channel type. The interactive mode is recommended for all RTC scenarios.

Return value

0 indicates the method call was successful. Any other value indicates a failure. 1: The SDK is not initialized or has been destroyed.

setAudioProfile

Sets the audio encoding mode and scenario mode.

public abstract int setAudioProfile(AliRtcAudioProfile profile, AliRtcAudioScenario scenario);

This method sets the audio encoding mode and audio scenario mode. For more information, see Common audio operations and configurations. The ARTC SDK uses the high-quality audio mode (AliRtcEngineHighQualityMode) and music scenario mode (AliRtcSceneMusicMode) by default. If the default settings do not meet your needs, call this method to change them.

When to call

Call this method only before you join a channel. You cannot reset the settings after you join a channel. You can reset them after you leave the channel.

Parameters

Parameter

Type

Description

profile

AliRtcAudioProfile

The audio collection or encoding mode parameter. The high-quality audio mode (AliRtcEngineHighQualityMode) is recommended.

Note

To interoperate with a Web client, set the sample rate to 48k.

  • AliRtcEngineLowQualityMode: Low-quality audio mode. Default sample rate is 8000 Hz, single channel, maximum bitrate is 12 kbps.

  • AliRtcEngineBasicQualityMode: Standard-quality audio mode. Default sample rate is 16000 Hz, single channel, maximum bitrate is 24 kbps.

  • AliRtcEngineHighQualityMode: Default sample rate is 48000 Hz, single channel, maximum bitrate is 64 kbps.

  • AliRtcEngineStereoHighQualityMode: Stereo high-quality audio mode. Default sample rate is 48000 Hz, dual channel, maximum bitrate is 80 kbps.

  • AliRtcEngineSuperHighQualityMode: Super high-quality audio mode. Default sample rate is 48000 Hz, single channel, maximum bitrate is 96 kbps.

  • AliRtcEngineStereoSuperHighQualityMode: Stereo super high-quality audio mode. Default sample rate is 48000 Hz, dual channel, maximum bitrate is 128 kbps.

scenario

AliRtcAudioScenario

The audio scenario mode parameter. It includes:

  • AliRtcSceneMusicMode (recommended): Music scenario. Uses software-based 3A algorithms and collects audio from the mobile phone for higher audio quality.

  • AliRtcSceneDefaultMode: Uses hardware-based 3A algorithms and can collect audio from Bluetooth devices.

Return value

0: Success. A value less than 0: Failure.

isAudioOnly

Checks whether the current mode is audio-only.

public abstract boolean isAudioOnly();

Return value

true: audio-only mode. false: audio and video mode.

setAudioOnlyMode

Sets whether to enable audio-only mode.

public abstract int setAudioOnlyMode(boolean audioOnly);

Parameters

Parameter

Type

Description

audioOnly

boolean

Sets the mode to audio-only or audio and video. Valid values:

  • true: Only audio is published and pulled.

  • false (default): Both audio and video are supported.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

joinChannel[1/3]

Joins a channel (single-parameter join).

public abstract int joinChannel(String token, String channelId, String userId, String userName);

This interface is used to join a channel. ARTC uses channels to organize users. You must join a channel to publish or subscribe to audio and video streams. This interface, joinChannel[2/3], and joinChannel[3/3] can all be used to join a channel. They differ in the authentication method and the user information that is passed, as follows:

  • This API is a single-parameter join method. Pass a token generated for a single-parameter join using Token-based authentication to join the channel. This API is recommended for joining channels in RTC scenarios.

  • joinChannel[2/3] is a multi-parameter interface for joining a channel. To use this interface, you must pass a multi-parameter channel joining token generated using Token-based authentication and the user information used to generate the token.

  • The joinChannel[3/3] method is used for Real-time Conversational AI scenarios. Pass a single-parameter join token and set the capabilityProfile user property based on the scenario.

Note

By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and push your own audio and video streams to remote users. If you want to cancel the default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="33438e1082mi8">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="243e9483a0suk">setDefaultSubscribeAllRemoteVideoStreams</a> before you call this API to disable the subscription to audio or video streams.

When to call

Call this method after creating the engine.

Limits

  • After you successfully join a channel, if you need to join another channel, you must first call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="4de6ecc1a4pa2">leaveChannel</a> to leave the current channel, and ensure that you receive the AliRtcEngineEventListener's <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="70c68b0236xdt">onLeaveChannelResult</a> callback before you can join another channel.

  • This method supports joining only one channel at a time.

  • Applications that use different App IDs cannot communicate with each other.

  • You do not need to call this method again if the SDK is retrying to join the channel after a failure.

Related callbacks

Calling this method successfully triggers the following callbacks:

  • The result of the local client joining a channel is returned through the AliRtcEngineEventListener's <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="712006e223y8z">onJoinChannelResult</a> callback.

  • After you successfully join a channel, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="40a9273affui1">onRemoteUserOnLineNotify</a> callback is triggered.

Parameters

Parameter

Type

Description

token

String

The authentication information for a single-parameter join.

channelId

String

The channel to join. This must be the same as the value used to generate the token.

userId

String

The user ID for joining the channel. This must be the same as the value used to generate the token.

userName

String

The display name of the user (not the user ID).

Return value

0 indicates the method call was successful. A non-zero value indicates a failure.

joinChannel[2/3]

Joins a channel (multi-parameter join).

public abstract int joinChannel(AliRtcAuthInfo authInfo, String userName);

This operation is used to join a channel. ARTC uses channels to organize users, and a user must join a channel to publish or subscribe to audio and video streams. This operation, along with joinChannel[1/3] and joinChannel[3/3], can be used to join a channel. The differences lie in the authentication method and the user information that is passed, as detailed below:

  • joinChannel[1/3] is the single-parameter API for joining a channel. Pass a token generated for a single-parameter join via Token authentication to join the channel. This API is recommended for joining a channel in RTC scenarios.

  • This API is a multi-parameter join interface. You must pass a multi-parameter join token generated using Token-based authentication and the user information that was used to generate the token.

  • joinChannel[3/3] is used for Real-time Conversational AI scenarios and requires you to pass a single-parameter join token and set the user property capabilityProfile based on the scenario.

Note
  • By default, when you join a channel, you subscribe to the audio and video streams of all other users in the channel and publish your own audio and video streams. If you want to cancel the default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="474adcf738uxu">setDefaultSubscribeAllRemoteAudioStreams</a> and setDefaultSubscribeAllRemoteVideoStreams before you call this API to disable the subscription to audio or video streams.

  • This is a multi-parameter join method. Before you call it, generate a multi-parameter join token as described in Token-based authentication.

Limits

  • If you need to switch to another channel after joining one, you must first call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="e2525ba6a0k3s">leaveChannel</a> to leave the current channel and wait for the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="6aefdfedb0op3">onLeaveChannelResult</a> callback from AliRtcEngineEventListener before you can join another channel.

  • This method supports joining only one channel at a time.

  • Applications that use different App IDs cannot communicate with each other.

Related callbacks

Calling this method successfully triggers the following callbacks:

  • The result of the local user joining a channel is notified through the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="fb41cdcfc6acj">onJoinChannelResult</a> callback in AliRtcEngineEventListener.

  • After you successfully join the channel, the remote user 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

AliRtcAuthInfo

Authentication information. The token is a multi-parameter token. Other parameters related to token generation must be consistent with those used during token generation and cannot be empty.

userName

String

The display name of the user (not the user ID). This can be empty.

Return value

0 indicates the method call was successful. A non-zero value indicates a failure.

joinChannel[3/3]

Joins a channel (single-parameter join).

public abstract int joinChannel(String token, AliRTCSdkChannelParam channelParam);

This interface is used to join a channel. Alibaba Real-Time Communication (ARTC) uses channels to organize users. You must join a channel to publish or subscribe to audio and video streams. This interface, joinChannel[1/3], and joinChannel[2/3] can all be used to join a channel. The differences are the authentication method and the user information that is passed, as follows:

  • joinChannel[1/3] is the recommended API for joining a channel with a single parameter in RTC scenarios. You can join a channel by passing a token generated using Token authentication.

  • joinChannel[2/3] is the API for joining a channel with multiple parameters. To use this API, you must use Token authentication to generate a token for joining with multiple parameters, and then pass the generated token along with the user information that was used to create it.

  • This API is used for the Real-time Conversational AI scenario, where you pass in the token to join a session as a single parameter and set the capabilityProfile user property based on the scenario. To talk with an AI agent, set this property to AliCapabilityProfileAiHuman.

Note

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 the default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="5423d42229iih">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="0112175788ybe">setDefaultSubscribeAllRemoteVideoStreams</a> before you call this method to disable the subscription to audio or video streams.

Limits

  • If you need to join another channel after successfully joining one, 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 from AliRtcEngineEventListener before you can join a channel again.

  • This method supports joining only one channel at a time.

  • Applications that use different App IDs cannot communicate with each other.

  • You do not need to call this method again if the SDK is retrying to join the channel after a failure.

Related callbacks

Calling this method successfully triggers the following callbacks:

  • The result of the local client joining a channel is notified through the AliRtcEngineEventListener's <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#89f5ad2d0bnd1" id="879ae2fa04zjd">onJoinChannelResult</a> callback.

  • After you successfully join a channel, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="9b5662c5a0nvf">onRemoteUserOnLineNotify</a> callback is triggered.

Parameters

Parameter

Type

Description

token

String

The single-parameter join token.

channelParam

AliRTCSdkChannelParam

The parameters for joining a channel. This is mainly used for Real-time Conversational AI scenarios and includes:

  • channelId: The channel ID. This must be consistent with the value used during token generation. This parameter can be omitted.

  • userId: The user ID used to join the channel. This must be the same as the value used during token generation. This parameter can be omitted.

  • userName: Any display name for the user (not the user ID). This parameter can be omitted.

  • capabilityProfile: The user property. You must configure this specifically for AI agent communication scenarios. Use the default value for non-AI agent communication scenarios.

Return value

0 indicates the method call was successful. A non-zero value indicates a failure.

leaveChannel

Leaves a channel. After you call this method, the SDK terminates real-time audio and video interaction and leaves the current channel.

public abstract int leaveChannel();
Note
  • This method is an asynchronous operation. A successful call does not mean that you have actually left the channel. You leave the channel only after the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="7e49937108skj">onLeaveChannelResult</a> callback is received.

  • After leaveChannel completes, destroy the engine and set it to null.

    mAliRtcEngine.leaveChannel();
    mAliRtcEngine.destroy();
    mAliRtcEngine = null;

When to call

  • Call this method when you need to leave the channel after joining it.

  • If you have already joined a channel and need to join another channel, call this method first to exit the current channel.

Related callbacks

  • Local client: After you call this method, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="80f5e30245vfn">onLeaveChannelResult</a> callback is triggered to notify you of the result of leaving the channel.

  • Remote side: After this API is called successfully, remote users receive 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 value

0 indicates the method call was successful. A non-zero value indicates a failure.

isInCall

Checks whether the user is in a channel.

public abstract boolean isInCall();

Return value

true: The user is in a channel. false: The user is not in a channel.

setClientRole

Sets the user role.

public abstract int setClientRole(AliRTCSdkClientRole clientRole);

This method sets the user role to streamer or viewer.

In interactive mode, before joining a channel:

  • If you set the user role to streamer, the SDK automatically publishes the local audio and video streams by default and receives the audio and video streams from other streamers.

  • If you set the user role to viewer, the SDK does not publish the local audio and video streams but receives the audio and video streams from other streamers.

When to call

You can call this method before or after joining a channel. You can call it before joining to set the user role or after joining to switch the user role.

Limits

This method is effective only in interactive mode, which means you must call the setChannelProfile method to set the channel profile to AliRTCSdkInteractiveLive.

In interactive mode, we recommend that you explicitly set the user role before you join a session.

Parameters

Parameter

Type

Description

clientRole

AliRTCSdkClientRole

The user role type. This is valid only in interactive mode.

getCurrentClientRole

Gets the user role.

public abstract AliRTCSdkClientRole getCurrentClientRole();

Return value

Returns the current user role.

refreshAuthInfo[1/2]

Refreshes the authentication information.

public abstract int refreshAuthInfo(AliRtcAuthInfo authInfo);

This method updates the authentication information. Tokens expire after a certain period, and the SDK cannot establish a connection with the server after expiration.

Note

Both this API and the refreshAuthInfo[2/2] operation update authentication information. This API is used to update tokens for multi-participant meetings, while refreshAuthInfo[2/2] is used to update tokens for single-participant meetings. For more information about token generation, see Token Authentication.

When to call

In the following situations:

  • When the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e9acb46a25uym" id="7e1510bec7s3s">onAuthInfoWillExpire</a> callback reports that the authentication information is about to expire, we recommend that you regenerate a Token on your server-side and then call this method to pass in the new Token.

  • If you do not update the token in time, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="97664f9e46fhp">onAuthInfoExpired</a> callback is triggered, which indicates that the authentication has expired. In this case, you must regenerate the token and then call joinChannel to rejoin the channel.

Parameters

Parameter

Type

Description

authInfo

AliRtcAuthInfo

Authentication information.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

refreshAuthInfo[2/2]

Refreshes the authentication information.

public abstract int refreshAuthInfo(String token);

This method updates the token. Tokens expire after a certain period, and the SDK cannot establish a connection with the server after expiration.

Note

Both this API and refreshAuthInfo[1/2] are used to update authentication information. This API updates the token for single-parameter meeting joins, whereas refreshAuthInfo[1/2] updates the token for multi-parameter meeting joins. For more information about token generation, see Token Authentication.

When to call

In the following situations, we recommend that you generate a new token on your server and then call this method to pass the new token:

  • 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 the Token is not updated in time, this triggers <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="3fd674e985gl8">onAuthInfoExpired</a>, indicating that authentication has expired, and you must then call joinChannel to rejoin the channel.

Parameters

Parameter

Type

Description

token

String

The authentication information for a single-parameter join.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

publishLocalAudioStream

Stops or resumes publishing the local video stream.

public abstract int publishLocalAudioStream(boolean enable);

This method is used to control whether to publish the local audio stream. By default, the SDK publishes the audio stream. To disable this behavior, call publishLocalAudioStream(false) before you join a meeting.

When to call

You can call this method before or after joining a channel. If you call it before joining, the setting takes effect when you join the channel.

Related callbacks

When the state of local audio stream ingest changes, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b7e3bb51c2ga9" id="4ced92c3f5hmj">onAudioPublishStateChanged</a> callback is triggered on the local client to report the latest audio stream ingest state, and the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="2b5460d448ga9">onRemoteTrackAvailableNotify</a> callback is triggered on the remote client to report 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:

  • true (default): Publish the audio stream.

  • false: Do not publish the audio stream.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

isLocalAudioStreamPublished

Queries whether the audio stream is being published.

public abstract boolean isLocalAudioStreamPublished();

Return value

true: The audio stream is being published. false: The audio stream is not being published.

setDefaultSubscribeAllRemoteAudioStreams

Sets whether to subscribe to remote audio streams 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 users who join the channel later. We recommend setting this to true unless you have specific requirements.

When to call

You can call this method before or after joining a channel.

  • Before joining a channel:

    • By default, the SDK subscribes to remote users' audio streams when joining a channel. If you want to change this behavior, call this method before joining the channel.

  • After joining a channel:

    • If you want to stop the default subscription, you can call setDefaultSubscribeAllRemoteAudioStreams(false). You will not subscribe to the audio streams of users who subsequently join the channel.

    • After stopping the default subscription, if you want to resume subscribing to a specific user's audio stream, call the subscribeRemoteAudioStream method. To resume subscribing to multiple users, call this method multiple times.

    • After you stop the default subscription, calling setDefaultSubscribeAllRemoteAudioStreams(true) resumes the audio streams of only the users who join the channel afterward. The audio streams of remote users who joined the channel while the subscription was stopped are not subscribed.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to subscribe to remote audio streams by default. Valid values:

  • true (default): Subscribe to remote audio streams by default.

  • false: Do not subscribe to remote audio streams by default.

Return value

0 indicates the method call was successful. Any other value indicates a 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 a specific remote user's audio stream. We recommend setting this to true unless you have specific requirements.

Note

By default, the SDK subscribes to the audio 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="#0155f66448env" id="d319c7806ej0h">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join the meeting to cancel this default configuration.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

sub

boolean

Stops or resumes pulling the audio stream of a specific remote user. Valid values:

  • true (default): Resume.

  • false: Stop.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

subscribeAllRemoteAudioStreams

Sets whether to subscribe to all remote audio streams.

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 you set it to false, the following occurs:

  • All remote audio streams in the current session stop being subscribed to.

  • New users who join the channel later are 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 a specific user's audio stream.

To resume subscription, call this method again and set it to true.

Note

By default, the SDK subscribes to the audio streams of all remote users when you join a channel. To change 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 you join the channel to disable this default configuration.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to subscribe to all remote audio streams. Valid values:

  • true (default): Subscribe to all remote audio streams.

  • false: Do not subscribe to all remote audio streams.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

publishLocalVideoStream

Sets whether to publish the camera stream.

public abstract int publishLocalVideoStream(boolean enable);

This method controls whether to publish the locally collected video stream.

Note

The SDK publishes the video stream by default. To disable video stream publishing, call publishLocalVideoStream(false) before joining a channel.

When to call

You can call this method before or after joining a channel.

If you call it before joining, the setting takes effect when you join the channel.

Related callbacks

When the local audio stream ingest result changes, the local client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#afe6d3c4b1rvg" id="8b70bc353aj68">onVideoPublishStateChanged</a> callback to notify of the latest audio stream ingest status, and the remote client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="176ee94b46lb7">onRemoteTrackAvailableNotify</a> callback to notify of changes to the remote user's audio and video stream.

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to publish the camera stream. Valid values:

  • true (default): Publish the camera stream.

  • false: Do not publish the camera stream.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

isLocalVideoStreamPublished

Queries whether the camera stream is being published.

public abstract boolean isLocalVideoStreamPublished();

Return value

true: The camera stream is being published. false: The camera stream is not being published.

setDefaultSubscribeAllRemoteVideoStreams

Sets whether to subscribe to remote video streams by default.

public abstract int setDefaultSubscribeAllRemoteVideoStreams(boolean sub);

This method sets whether to subscribe to remote video streams 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 a channel, you will not receive the video streams of users who join the channel later.

After you stop receiving video streams, if you want to resume receiving, call subscribeRemoteVideoStream and specify the remote user ID you want to receive. If you want to resume receiving video streams from multiple users, call subscribeRemoteVideoStream multiple times. setDefaultSubscribeAllRemoteVideoStreams(true) only resumes receiving the video streams of users who join the channel later.

This method sets whether to subscribe to remote users' video streams by default.

Note

By default, the SDK subscribes to remote users' audio and video streams when joining a channel. If you want to change this behavior, call this method before joining the channel.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to subscribe to remote video streams by default. Valid values:

  • true (default): Subscribe by default.

  • false: Do not subscribe by default.

Return value

0 indicates the method call was successful. Any other value indicates a 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.

Note

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 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 uid

track

AliRtcVideoTrack

Video stream type.

sub

boolean

Specifies whether to receive the specified user's video stream.

  • true: Receive the specified user's video stream.

  • false: Stop receiving the specified user's video stream.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call 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 you set it to false, the following occurs:

  • All remote video streams in the current session stop being subscribed to.

  • New users who join the meeting later will also no longer subscribe (even if you set <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="8661e30c89dum">setDefaultSubscribeAllRemoteVideoStreams</a>(true) to subscribe by default).

  • You cannot use <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b738a1b498bc1" id="19b0cea8593i5">subscribeRemoteVideoStream</a> to individually control the video stream of a specific user.

To resume subscription, call this method again and set it to true.

Note

By default, the SDK subscribes to the video streams of all remote users when you join a meeting. To modify this behavior, you can call setDefaultSubscribeAllRemoteVideosStreams(false) before you join the meeting to cancel this default configuration.

Parameters

Parameter

Type

Description

sub

boolean

Stops or resumes receiving all remote video streams. Valid values:

  • true (default): Resume.

  • false: Stop.

Return value

0 indicates the method call was successful. Any other value indicates a 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 merges the subscription of remote audio and video streams.

Note

In this interface, the AliRtcVideoTrackNo of AliRtcVideoTrack is invalid, and setting it has no effect.

Related interfaces

Unlike <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 uses the two Boolean parameters subVideo and subAudio to determine whether to subscribe to remote audio and video streams, while the videoTrack parameter controls which video stream to pull.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

videoTrack

AliRtcVideoTrack

Video stream type.

subVideo

boolean

Stops or resumes pulling the video stream of a specific remote user. Valid values:

  • true (default): Resume.

  • false: Stop.

subAudio

boolean

Stops or resumes pulling the audio stream of a specific remote user. Valid values:

  • true (default): Resume.

  • false: Stop.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

subscribeRemoteMediaStream[2/2]

Stops/resumes subscribing to a remote user's audio and video streams.

public abstract int subscribeRemoteMediaStream(String uid, AliRtcVideoTrack videoTrack, AliRtcAudioTrack audioTrack) ;

This method merges the subscription of remote audio and video streams.

Related interfaces

Compared to subscribeRemoteMediaStream[1/2], this interface uses a single call with the videoTrack and audioTrack parameters to inform the SDK of the desired subscription state. For example:

  • If you want to subscribe to the camera and microphone streams, set videoTrack to AliRtcVideoTrackCamera and audioTrack to AliRtcAudioTrackMic when you make the call.

  • If you want to unsubscribe from the camera stream but keep the microphone, set videoTrack to AliRtcVideoTrackNo and audioTrack to AliRtcAudioTrackMic when you call the method again.

  • To cancel both, set videoTrack and audioTrack to AliRtcVideoTrackNo and AliRtcAudioTrackNo respectively in a subsequent call.

  • To subscribe to both the camera stream and the screen sharing stream simultaneously, set videoTrack to AliRtcVideoTrackBoth. The same applies to audio.

Parameters

Parameter

Type

Description

uid

String

User ID, a unique identifier assigned by the App server.

videoTrack

AliRtcVideoTrack

Video stream type.

audioTrack

AliRtcAudioTrack

Audio stream type.

Return value

  • 0: Success.

  • <0: Failure.

subscribeRemoteDestChannelStream

Subscribes 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

Remote channel ID.

uid

String

Remote user ID.

track

AliRtcVideoTrack

Video stream to subscribe to.

sub_audio

boolean

Stops or resumes pulling the audio stream of a specific remote user. Valid values:

  • true (default): Resume.

  • false: Stop.

sub

boolean

Stops or resumes subscribing to a specific user's stream across channels.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

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

Remote target channel ID.

videoTrack

AliRtcVideoTrack

Video stream type to subscribe to.

sub_audio

boolean

Specifies whether to subscribe to remote users' audio streams.

  • true: Subscribe to audio streams of users in the target channel.

  • false: Stop subscribing to audio streams of users in the target channel.

sub

boolean

Stops or resumes subscribing to a specified user stream across channels.

  • true: Subscribe.

  • false: Unsubscribe.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed.

setRemoteAudioVolume

Adjusts the playback volume of a pulled stream.

public abstract int setRemoteAudioVolume(String uid, int volume);

With this interface, the local user can adjust the playbackvolume of a specified user's audio stream on the local device.

Note

This setting only affects the listening experience on the local device.

Parameters

Parameter

Type

Description

uid

String

User ID. A unique identifier for the user, usually assigned by the App server.

volume

int

Playback volume. The range is [0, 100].

  • 0: Mute.

  • 100: Original volume.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed. For example, the volume value is invalid.

muteLocalMic

Stops or resumes sending local audio data.

public abstract int muteLocalMic(boolean mute, AliRtcMuteLocalAudioMode mode);
Note

Muting means sending silent frames in the audio stream. The collection and encoding modules continue to work.

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 that user is muted.

Parameters

Parameter

Type

Description

mute

boolean

Stops or resumes sending local audio data. Valid values:

  • true: Send silent frames for local audio.

  • false (default): Resume.

mode

AliRtcMuteLocalAudioMode

Mute mode. The default is microphone mute mode.

Return value

0 indicates the method call was successful. Any other value indicates a failure. Muting only sends silent frames for audio data. The collection and encoding modules continue to work.

muteRemoteAudioPlaying

Stops or resumes remote audio playback.

public abstract int muteRemoteAudioPlaying(String uid, boolean mute);

This API is used only to stop or resume the playback of audio from a specified remote user. It does not affect the 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

User ID.

mute

boolean

Stops or resumes remote audio playback. Valid values:

  • true: Stop playback.

  • false (default): Resume playback.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

muteAllRemoteAudioPlaying

Stops or resumes all remote audio playback.

public abstract int muteAllRemoteAudioPlaying(boolean mute);

This method stops or resumes all remote audio playback.

Note

This method only stops playback. Stream pulling and decoding are not affected.

When to call

You can set this before or after joining a channel.

Parameters

Parameter

Type

Description

mute

boolean

Stops or resumes all remote audio playback. Valid values:

  • true: Stop playback.

  • false (default): Resume playback.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

startAudioCapture[1/2]

Enables audio collection.

public abstract int startAudioCapture();

This interface is used to start audio capture. You can call this interface before you join a meeting to start audio capture in advance. If you do not call this interface, the SDK automatically controls the audio capture device. To start audio capture again after you stop it by calling stopAudioCapture, call this interface.

When to call

You can call this method before or after joining a channel.

Related interfaces

<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b71a48f4b84n0" id="4565abdceeq8i">startAudioCapture[2/2]</a> uses parameters to control whether the audio capture device remains enabled after you leave a meeting.

Related callbacks

After you call this method to change the local audio collection status, you can get the status change through the onLocalAudioStateChanged callback.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

startAudioCapture[2/2]

Enables audio collection.

public abstract int startAudioCapture(boolean keepAlive);

Muting disables microphone capture.

This method controls enabling audio collection. You can also call it before joining a channel to enable audio collection in advance. If you do not set this, the SDK automatically controls the audio collection device.

When to call

You can call this method before or after joining a channel.

Related interfaces

Compared to startAudioCapture[1/2], this API lets you use the keepAlive parameter to control whether the capture device remains on after you leave the session.

Related callbacks

After you call this method to change the local audio collection status, you can get the status change through the onLocalAudioStateChanged callback.

Parameters

Parameter

Type

Description

keepAlive

boolean

The status of the collection device after leaving the channel. Valid values:

  • true: The collection device remains enabled after leaving the channel.

  • false (default): The collection device is disabled after leaving the channel.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

stopAudioCapture

Disables audio collection.

public abstract int stopAudioCapture();

The SDK enables audio collection by default. Without special configuration, actions such as starting a preview or joining a channel automatically start audio collection. To stop audio device collection, call this method.

Related callbacks

After you call this method to change the local audio collection status, you can get the status change through the onLocalAudioStateChanged callback.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setDefaultAudioRoutetoSpeakerphone

Sets whether the default audio output is the speaker.

public abstract int setDefaultAudioRoutetoSpeakerphone(boolean defaultToSpeakerphone);

This method sets the default audio routing device before joining a channel. You can choose to output to the earpiece or speaker by default. The SDK defaults to the speaker. If you want to change this default configuration, call this method before joining a channel.

The audio routing priority is predefined in the SDK and automatically switches based on the connection status of peripherals. The priority order is as follows: Wired headset > Bluetooth headset > User settings > Default settings. Therefore, if no peripherals are connected and the audio route is not set using enableSpeakerphone, the default settings are used.

For more information about audio routing settings, see Audio routing settings.

Mobile devices generally have two audio routing devices: the earpiece and the speaker.

  • When the audio route is the earpiece, the sound is quieter and can only be heard clearly when the ear is close. It offers better privacy and is suitable for answering calls.

  • When the audio route is the speaker, the sound is louder and can be heard without holding the phone to your face, enabling a "hands-free" feature.

Related interfaces

This API is used to modify the default audio routing settings. The enableSpeakerphone API is used to set the current routing device.

When to call

You can call this method before or after joining a channel.

Parameters

Parameter

Type

Description

defaultToSpeakerphone

boolean

Specifies whether to use the speaker by default.

  • true: Speaker mode (default speaker).

  • false: Earpiece mode.

Return value

  • 0: The method call succeeded.

  • <0: The method call failed.

enableSpeakerphone

Sets the audio output to the earpiece or speaker.

public abstract int enableSpeakerphone(boolean enable);

This method sets the current audio playback device after joining a channel, choosing between the earpiece and the speaker. If this feature is not set, the device set by the default audio routing is used for playback.

The audio routing priority is predefined in the SDK and switches automatically based on the connection status of peripherals. The priority 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 interfaces

<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. This API sets the current routing device.

Parameters

Parameter

Type

Description

enable

boolean

Sets the audio output to the earpiece or speaker. Valid values:

  • true (default): Speaker mode.

  • false: Earpiece mode.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

isSpeakerOn

Gets whether the current audio output is the earpiece or speaker.

public abstract boolean isSpeakerOn();

Return value

true: Speaker. false: Earpiece.

enableAudioVolumeIndication

Enables user volume indication.

public abstract int enableAudioVolumeIndication(int interval, int smooth, int reportVad);

This interface allows the SDK to periodically report volume-related information to your app about the local user who is publishing a stream and the remote user with the highest instantaneous volume. To use this feature, implement the AliRtcAudioVolumeObserver class and call the registerAudioVolumeObserver interface to register the receiving object.

When to call

You can call this method before or after joining a channel.

Related callbacks

After this method is called successfully, if there are publishing users in the channel, the SDK triggers the following two callbacks at the set time interval:

  • The speaker's audio volume is notified through the AliRtcAudioVolumeObserver#onAudioVolume callback. The callback frequency is determined by the interval.

  • Voice activity detection. When an active user is detected, the speaker's uid is returned through the AliRtcAudioVolumeObserver#onActiveSpeaker callback.

Parameters

Parameter

Type

Description

interval

int

Time interval.

  • Unit: ms.

  • Default value: 300 ms.

  • Range: Minimum value ≥ 10 ms. We recommend setting it to 300 ms to 500 ms. A value ≤ 0 disables the volume and speaker indication features.

smooth

int

Smoothing coefficient. A larger value means a higher degree of smoothing, while a smaller value means a lower degree of smoothing and better real-time performance.

  • Default value: 3.

  • Range: 0 to 9. We recommend setting it to 3.

reportVad

int

Local voice activity detection switch.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

enableEarBack

Enables in-ear monitoring.

public abstract int enableEarBack(boolean enable);

This method enables or disables the in-ear monitoring feature. We recommend enabling in-ear monitoring when wearing headphones (wired or Bluetooth) for better results.

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:

  • true: Enable in-ear monitoring.

  • false (default): Disable in-ear monitoring.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setEarBackVolume

Sets the in-ear monitoring volume.

public abstract int setEarBackVolume(int volume) ;

This method sets the volume for in-ear monitoring. It takes effect only after you enable the in-ear monitoring feature by calling enableEarBack.

When to call

You can call this method before or after joining a channel.

Parameters

Parameter

Type

Description

volume

int

Volume. The range is [0, 100]. The default value is 100.

  • 0: Mute.

  • 100: (Default) Original volume.

Return value

  • 0: The method call succeeded.

  • <0: The method call failed.

startAudioPlayer

Turns on the audio playback device.

public abstract int startAudioPlayer();

This method can control enabling audio playback in advance. If you do not set this, the SDK automatically enables audio playback after subscribing to an audio stream.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

stopAudioPlayer

Turns off the audio playback device.

 public abstract int stopAudioPlayer();

This method stops audio playback and corresponds to startAudioPlayer.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

setPlayoutVolume

Sets the local playback volume.

public abstract int setPlayoutVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

Playback volume. The range is [0, 400].

  • 0: Mute.

  • 100: Original volume.

  • >100: Increase volume.

Return value

  • 0: Success.

  • Non-zero: Failure.

setRecordingVolume

Sets the recording volume.

public abstract int setRecordingVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

Recording volume. The range is [0, 400].

  • 0: Mute.

  • 100: Original volume.

  • >100: Increase volume.

Return value

  • 0: Success.

  • Non-zero: Failure.

playAudioFileTest

Plays an audio file.

public abstract int playAudioFileTest(String filePath) ;

This method plays an audio file before joining a channel to test audio playback.

When to call

You can only call this method before joining a channel.

Limits

Multiple calls will overwrite each other. A new call stops any file that is currently playing.

Parameters

Parameter

Type

Description

filePath

filePath

The file path.

Return value

  • 0: Success.

  • Non-zero: Failure.

stopAudioFileTest

Stops playing the audio file.

public abstract int stopAudioFileTest();

This method corresponds to playAudioFileTest and stops playing the audio file.

Limits

You can only call this method before joining a channel.

Return value

  • 0: Success.

  • Non-zero: Failure.

startAudioCaptureTest

Enables audio collection device detection before a call.

public abstract int startAudioCaptureTest();

You can use this method to start an audio capture test to check if your local audio capture device is working properly before a call. After you call this method, the SDK reports the volume information of the capture device to you through the AliRtcAudioVolumeObserver::OnTestAudioVolume callback.

When to call

Call this method before you join a channel. After the test is complete, make sure that you call stopAudioCaptureTest to stop the device detection and prevent issues that are caused by device occupation.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

stopAudioCaptureTest

Disables audio collection detection.

public abstract int stopAudioCaptureTest();

This method stops audio capture device detection. You must call this method to stop the test after calling startAudioCaptureTest.

When to call

Call this before joining a channel.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

setAudioEffectVoiceChangerMode

Sets the voice changer effect mode.

public abstract int setAudioEffectVoiceChangerMode(AliRtcAudioEffectVoiceChangerMode mode);

Parameters

Parameter

Type

Description

mode

AliRtcAudioEffectVoiceChangerMode

Voice changer effect mode. The default value is AliRtcSdk_AudioEffect_Voice_Changer_OFF (disabled).

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectPitchValue

Sets the pitch shifting parameter.

public abstract int setAudioEffectPitchValue(double value);

Parameters

Parameter

Type

Description

value

double

The parameter range is [0.5, 2.0]. The default value is 1.0, which means the pitch is unchanged.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectReverbMode

Sets the reverberation effect mode.

public abstract int setAudioEffectReverbMode(AliRtcAudioEffectReverbMode mode);

Parameters

Parameter

Type

Description

mode

AliRtcAudioEffectReverbMode

Reverberation effect mode. The default value is AliRtcAudioEffectReverb_Off (disabled).

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectReverbParamType

Sets the reverberation effect type and specific parameters.

public abstract int setAudioEffectReverbParamType(AliRtcAudioEffectReverbParamType type, float value);

Parameters

Parameter

Type

Description

type

AliRtcAudioEffectReverbParamType

Reverberation effect parameter.

value

float

Specific parameter value.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectBeautifyMode

Sets the preset voice beautification effect mode.

public abstract int setAudioEffectBeautifyMode(AliRtcAudioEffectBeautifyMode mode);

This method sets some preset voice beautification modes within the SDK. It is suitable for scenarios with voice beautification needs, such as voice live streaming, karaoke, and voice social networking. By selecting different beautification modes, you can change the auditory effect of the human voice, such as enhancing magnetism or improving clarity, thereby improving 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

AliRtcAudioEffectBeautifyMode

Voice beautification effect mode. See the enumeration definition for details.

Return value

  • 0: Success.

  • Non-zero: Failure.

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 collected human voice or audio signals. By adjusting the gain (in dB) of one of the 10 fixed frequency bands, you can customize the timbre. It is suitable for scenarios such as voice clarity optimization, human voice enhancement, and noise reduction assistance.

The equalizer supports adjusting the full audio spectrum from 31 Hz to 16 kHz, with a total of 10 standard frequency bands. The gain for each band can be set independently, ranging from -15 to 15 dB, with a default of 0 dB (no enhancement or attenuation).

Limits

  • You cannot use the equalizer before the beautify mode is enabled. You must call this interface after calling setAudioEffectBeautifyMode.

Parameters

Parameter

Type

Description

bandIndex

AliRtcAudioEffectEqualizationBandFrequency

The index of the frequency band to be adjusted, corresponding to a segment of the center frequency (31 Hz to 16 kHz).

gain

float

Gain value in dB. The range is [-15, 15].

Return value

0: Success.

Non-zero: Failure.

addExternalAudioStream

Adds an external audio stream.

public abstract int addExternalAudioStream(AliRtcExternalAudioStreamConfig config);

This method adds a new external audio stream. The steps are as follows:

  1. Call the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#42b363024fich" id="20c33a9acb0ui">addExternalAudioStream</a> API to add an external audio stream and obtain the external audio stream ID.

  2. 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 to the created audio stream.

  3. When the call ends, you need to call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0333f86114078" id="16d826dedcli6">removeExternalAudioStream</a> to remove the external audio stream.

To publish custom-collected audio in a channel, see Custom audio collection.

Parameters

Parameter

Type

Description

config

AliRtcExternalAudioStreamConfig

External audio stream configuration.

Return value

A value greater than 0 indicates the method call was successful and is the external audio stream ID. Any other value indicates a failure.

pushExternalAudioStreamRawData

Inputs external audio stream data.

public abstract int pushExternalAudioStreamRawData(int streamId, AliRtcAudioFrame rawData);

This method inputs data into a specified audio stream. The steps are as follows:

  1. Call the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#42b363024fich" id="8822f2932e9ep">addExternalAudioStream</a> API to add an external audio stream and obtain the external audio stream ID.

  2. 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 into the created audio stream.

  3. When the call ends, you need to call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0333f86114078" id="106c7aefa27c0">removeExternalAudioStream</a> to remove the external audio stream.

To publish custom-collected audio in a channel, see Custom audio collection.

When to call

Call this after joining a channel.

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID.

rawData

AliRtcAudioFrame

Audio data.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setExternalAudioStreamPublishVolume

Sets the external audio stream ingest volume.

public abstract int setExternalAudioStreamPublishVolume(int streamId, int publishVolume);

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID.

publishVolume

int

Ingest volume. The range is [0, 100].

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getExternalAudioStreamPublishVolume

Gets the external audio stream ingest volume.

public abstract int getExternalAudioStreamPublishVolume(int streamId);

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID.

Return value

[0, 100] Ingest volume. < 0: Failure.

setExternalAudioStreamPlayoutVolume

Sets the external audio stream playback volume.

public abstract int setExternalAudioStreamPlayoutVolume(int streamId, int playoutVolume);

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID.

playoutVolume

int

Playback volume. The range is [0, 100].

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getExternalAudioStreamPlayoutVolume

Gets the external audio stream playback volume.

public abstract int getExternalAudioStreamPlayoutVolume(int streamId);

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID.

Return value

[0, 100] Playback volume. < 0 indicates a failure.

removeExternalAudioStream

Deletes an external audio stream.

public abstract int removeExternalAudioStream(int streamId);

This method removes the corresponding external audio stream based on the provided streamId. It corresponds to the addExternalAudioStream method.

When to call

If you want to use the custom audio input feature, you need to call the addExternalAudioStream method to add an audio stream and get the external audio stream ID. Then, call the pushExternalAudioStreamRawData method to input your audio data into the SDK. When you want to stop custom audio input, call this method to remove the corresponding external audio stream and clean up resources.

Parameters

Parameter

Type

Description

streamId

int

External audio stream ID. This is the return value when the addExternalAudioStream method is called successfully.

Return value

  • 0: Success.

  • <0: Failure. An error code is returned.

getAudioFileInfo

Gets audio file information.

public abstract int getAudioFileInfo(String fileName);

You can call this asynchronous API to obtain the duration information of a file. You can obtain the audio file information through onAudioFileInfo.

Parameters

Parameter

Type

Description

fileName

String

Audio file path.

Return value

  • 0: Success.

  • Non-zero: An error code is returned.

startAudioAccompany

Starts accompaniment mixing.

public abstract int startAudioAccompany(String fileName, AliRtcAudioAccompanyConfig config) ;

This method plays a local or online accompaniment file. It is an asynchronous method. After you call this method, you can listen to the accompaniment playback status through AliRtcEngineNotify#onAudioAccompanyStateChanged.

When to call

You can call this method after joining a channel.

Limits

Unlike sound effects, only one accompaniment can be played at a time. Repeated calls will overwrite the playback of the previous accompaniment.

Parameters

Parameter

Type

Description

fileName

String

Accompaniment file path.

config

AliRtcAudioAccompanyConfig

Accompaniment playback configuration, including whether to play locally only, whether to replace the microphone, number of loops, starting position, volume, and other settings.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

stopAudioAccompany

Stops accompaniment mixing.

public abstract int stopAudioAccompany() ;

This method corresponds to startAudioAccompany and stops accompaniment playback.

When to call

You can call this method before or after joining a channel.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

setAudioAccompanyVolume

Sets the accompaniment volume, including local playback volume and ingest volume.

public abstract int setAudioAccompanyVolume( int volume) ;

This method sets the accompaniment volume for both local playback and stream ingest. In addition, setAudioAccompanyPlayoutVolume and setAudioAccompanyPublishVolume set only the local playback volume and the accompaniment stream ingest volume, respectively.

Parameters

Parameter

Type

Description

volume

int

Accompaniment volume. The range is [0, 100].

0: Mute.

100: Original file volume.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

setAudioAccompanyPublishVolume

Sets the accompaniment ingest volume.

public abstract int setAudioAccompanyPublishVolume(int volume) ;

Parameters

Parameter

Type

Description

volume

int

Accompaniment volume. The range is [0, 100].

0: Mute.

100: Original file volume.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

getAudioAccompanyPublishVolume

Gets the accompaniment ingest volume.

public abstract int getAudioAccompanyPublishVolume() ;

Return value

The ingest volume of the accompaniment music.

  • [0-100]: Success.

  • Other: Error code.

setAudioAccompanyPlayoutVolume

Sets the accompaniment local playback volume.

public abstract int setAudioAccompanyPlayoutVolume(int volume) ;

Parameters

Parameter

Type

Description

volume

int

Accompaniment volume. The range is [0, 100].

0: Mute.

100: Original file volume.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

getAudioAccompanyPlayoutVolume

Gets the accompaniment local playback volume.

public abstract int getAudioAccompanyPlayoutVolume() ;

Return value

The local playback volume of the accompaniment music.

  • [0-100]: Success.

  • Other: Error code.

pauseAudioAccompany

Pauses accompaniment mixing.

public abstract int pauseAudioAccompany();

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

resumeAudioAccompany

Resumes accompaniment mixing.

public abstract int resumeAudioAccompany();

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

getAudioAccompanyDuration

Gets the duration of the accompaniment file, in milliseconds.

public abstract int getAudioAccompanyDuration();

This method gets the duration of the current accompaniment file.

Return value

  • >=0: Duration of the accompaniment file.

  • <0: Failure. An error code is returned.

getAudioAccompanyCurrentPosition

Gets the playback progress of the accompaniment file, in milliseconds.

public abstract int getAudioAccompanyCurrentPosition();

This method gets the playback progress of the current accompaniment file, in milliseconds.

Return value

  • >=0: Playback progress of the accompaniment file.

  • <0: Failure. An error code is returned.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

public abstract int setAudioAccompanyPosition(int posMs);

This method actively sets the playback progress of the accompaniment, for features such as dragging a progress bar. After this method is called successfully, the accompaniment file will play from the corresponding posMs position.

Parameters

Parameter

Type

Description

posMs

int

Progress bar position, in milliseconds.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

preloadAudioEffect

Preloads a sound effect file.

public abstract int preloadAudioEffect(int soundId, String filePath);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

filePath

String

Sound effect file path.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

unloadAudioEffect

Deletes a preloaded sound effect file.

public abstract int unloadAudioEffect(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a 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 to the sound effect file by the user.

filePath

String

Sound effect file path.

cycles

int

Number of loops. -1 means loop indefinitely.

publish

boolean

Specifies whether to publish the sound effect audio stream to remote users. Valid values:

  • true: Publish the sound effect audio stream to remote users.

  • false (default): Do not publish the sound effect audio stream to remote users.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

stopAudioEffect

Stops playing a sound effect.

public abstract int stopAudioEffect(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

stopAllAudioEffects

Stops playing all sound effects.

public abstract int stopAllAudioEffects();

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectPublishVolume

Sets the sound effect ingest mixing volume.

public abstract int setAudioEffectPublishVolume(int soundId, int volume);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

volume

int

Mixing volume. The range is 0 to 100. The default value is 50.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getAudioEffectPublishVolume

Gets the ingest sound effect volume.

public abstract int getAudioEffectPublishVolume(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAudioEffectPlayoutVolume

Sets the local playback volume for a sound effect.

public abstract int setAudioEffectPlayoutVolume(int soundId, int volume);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

volume

int

Mixing volume. The range is 0 to 100. The default value is 50.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getAudioEffectPlayoutVolume

Gets the local playback volume for a sound effect (Android and iOS).

public abstract int getAudioEffectPlayoutVolume(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setAllAudioEffectsPublishVolume

Sets the ingest mixing volume for all sound effects.

public abstract int setAllAudioEffectsPublishVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

Mixing volume. The range is 0 to 100. The default value is 50.

Return value

0 indicates the method call was successful. Any other value indicates a 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

Mixing volume. The range is 0 to 100. The default value is 50.

Return value

0 indicates the method call was successful. Any other value indicates a 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

AliRtcRecordType

Recording type.

recordFormat

AliRtcRecordFormat

Format type (WAV, AAC, MP4).

filePath

String

Recording file name.

audioConfig

AliRtcRecordAudioConfig

Audio configuration.

videoConfig

AliRtcRecordVideoConfig

Video configuration.

maxSize

long

Maximum file size.

maxDuration

long

Maximum file duration.

Return value

TRUE: Success. Other: Failure.

Note
  • When you record a video stream, call this API after the stream ingest is successful (onVideoPublishStateChanged). This API records the locally encoded video stream and saves it locally.

  • When recording an audio stream, the recorded file is a mix of local and remote audio.

stopRecord

Stops recording a media file.

  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 assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

pauseAllAudioEffects

Pauses all sound effects.

public abstract int pauseAllAudioEffects();

Return value

0 indicates the method call was successful. Any other value indicates a failure.

resumeAudioEffect

Resumes playing a sound effect.

public abstract int resumeAudioEffect(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

resumeAllAudioEffects

Resumes playing all sound effects.

public abstract int resumeAllAudioEffects();

Return value

0 indicates the method call was successful. Any other value indicates a failure.

createRenderSurfaceView

Creates a SurfaceView rendering view.

public abstract SophonSurfaceView createRenderSurfaceView(Context context);

You must call this method to display the video view, instead of creating a SurfaceView directly. The calling method is as follows:

  • Assign the return value to AliRtcVideoCanvas#view.

  • Call setLocalViewConfig to set the local preview display view or call setRemoteViewConfig to set the remote preview display view.

When to call

You can call this method before or after joining a channel.

Limits

Call this method in the main thread.

Parameters

Parameter

Type

Description

context

Context

The context of the Android Activity.

setLocalViewConfig

Sets the rendering window and drawing parameters for the local preview.

public abstract int setLocalViewConfig(AliRtcVideoCanvas viewConfig, AliRtcVideoTrack track);

This method is used to set the local preview view. Calling this method attaches the display window (view) for the local video stream and sets parameters for the local user view, such as the rendering mode, mirror mode, and rotation angle. It only affects the local user's preview screen and does not affect the ingested video stream. To set the remote user interface view, call setRemoteViewConfig.

Note
  • If the view parameter in AliRtcVideoCanvas is empty, rendering stops.

  • To reset the renderMode parameter of AliRtcVideoCanvas during playback, keep the other parameters unchanged and only modify renderMode.

  • To reset the mirrorMode parameter of AliRtcVideoCanvas during playback, keep the other parameters unchanged and only modify mirrorMode.

  • We recommend explicitly calling 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

AliRtcVideoCanvas

Rendering parameters, including the rendering window and rendering method.

track

AliRtcVideoTrack

Video stream type.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setRemoteViewConfig

Sets the rendering window and drawing parameters for a remote video.

public abstract int setRemoteViewConfig(AliVideoCanvas canvas, String uid,AliRtcVideoTrack track);

This method attaches a display view to a specified video stream from a remote user and sets display settings for the remote view, such as the rendering mode, mirror mode, and rotation angle. This affects only the video image that the local user sees. To set the local preview view, call setLocalViewConfig.

  • If the view parameter in AliRtcVideoCanvas is empty, rendering stops.

  • To reset the renderMode parameter of AliRtcVideoCanvas during playback, keep the other parameters unchanged and only modify renderMode.

  • To reset the mirrorMode parameter of AliRtcVideoCanvas during playback, keep the other parameters unchanged and only modify mirrorMode.

When to call

We recommend calling this when you receive the onRemoteTrackAvailableNotify callback, which is when the remote user's video is available.

Parameters

Parameter

Type

Description

canvas

AliRtcVideoCanvas

Rendering parameters, including the rendering window and rendering method.

uid

String

User ID.

track

AliRtcVideoTrack

The video stream type to set.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setCameraCapturerConfiguration

Sets the camera capture preferences.

public abstract int setCameraCapturerConfiguration(AliEngineCameraCapturerConfiguration cameraCapturerConfiguration);

This method configures camera capture preferences, such as camera direction and capture frame rate.

When to call

You must set this before you turn on the camera. For example, call it before the following operations:

  • startPreview (start preview)

  • joinChannel (join channel)

Parameters

Parameter

Type

Description

cameraCapturerConfiguration

AliEngineCameraCapturerConfiguration

Camera capture preferences, including camera direction, frame rate, and more. Default values:

  • preference:

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_AUTO: The SDK automatically adjusts capture parameters.

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_PREVIEW: High-definition preview. Capture prioritizes video preview quality.

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE: Capture selects the resolution closest to the publishing resolution, prioritizing device performance.

  • cameraDirection: AliRtcCameraDirection.CAMERA_FRONT. Front camera is the default.

  • fps: -1 indicates using the encoder's internal frame rate setting. The default is 15.

  • cameraCaptureProfile: 0. Specifies a specific resolution for video capture.

  • disableVideoCaptureReverse: Do not flip the captured video frame based on the aspect ratio setting. -1: Default. 0: Not effective. 1: Effective.

  • captureObserverOriginal: Whether to callback the original videoframe data. -1: Default. 0: Disabled. 1: Enabled.

  • textureEncode: Whether to use texture encoding. -1: Default. 0: Disabled. 1: Enabled.

  • cameraTextureCapture: Whether the camera enables texture capture. -1: Default. 0: Disabled. 1: Enabled.

A value of -1 indicates using the SDK's internal default settings.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

enableLocalVideo

Disables or re-enables local video collection.

public abstract int enableLocalVideo(boolean enable);

This method controls enabling and disabling local video collection. When local video collection is disabled, both the local preview and the published stream have no video data, but this does not affect receiving remote video. If you call this method to disable local camera collection, both the local preview and the remote published stream will freeze on the last frame.

Note

Local video collection is enabled by default in the SDK.

When to call

You can call this method before or after joining a channel.

Related callbacks

After this method is called successfully, the remote user is notified through the onUserVideoEnabled callback.

Parameters

Parameter

Type

Description

enable

boolean

Disables or re-enables local video collection. Valid values:

  • true (default): Re-enable.

  • false: Disable.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

muteLocalCamera

Stops or resumes sending local video data.

public abstract int muteLocalCamera(boolean mute, AliRtcVideoTrack track);

When publishing a stream, you can call this method to publish all-black video frames. The local preview remains normal, and the collection, encoding, and sending modules continue to work, but the video content is black frames.

Note

You can call this method to control whether to send black frames on a specified video stream. This does not affect the collection and data transmission processes. To disable collection, call the enableLocalVideo method. To stop sending video data, call the publishLocalVideoStream method or call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7558afe6accq4" id="ee17216e55r3t">enableLocalVideo</a> stop collection.

Parameters

Parameter

Type

Description

mute

boolean

Stops or resumes sending local video data. Valid values:

  • true: Stop.

  • false (default): Resume.

track

AliRtcVideoTrack

The type of video stream whose publishing status needs to be changed.

Return value

0 indicates the method call was successful.

isCameraOn

Checks whether the camera is on.

public abstract boolean isCameraOn();

Return value

true: The camera is on. false: The camera is not on.

setVideoEncoderConfiguration

Sets the video encoding properties.

public abstract void setVideoEncoderConfiguration(AliRtcVideoEncoderConfiguration config);

This method sets the video parameters for the video stream encoding properties, such as resolution, frame rate, bitrate, and video orientation. We recommend calling this method for all video scenarios.

Note

All set parameters have corresponding range limits. If a set parameter is outside the valid range, the SDK automatically adjusts it.

When to call

You can call this method before or after joining a channel. If you only need to set the camera stream video encoding properties once per session, we recommend calling it before joining the channel.

Limits

Both the mirrorMode of this method and setVideoMirrorMode can set the video publishing mirror. We recommend using only one. Using multiple methods at the same time can cause the mirror effects to stack, leading to a failed or incorrect mirror setting.

Parameters

Parameter

Type

Description

config

AliRtcVideoEncoderConfiguration

Predefined encoding properties. Default values:

  • dimensions: [640, 480]. The maximum value is 1920x1080. You need to set the resolution.

  • frameRate: 15

  • bitrate: 0. The SDK calculates a suitable encoding bitrate based on the video resolution and bitrate.

  • keyFrameInterval: Keyframe interval in milliseconds. The default is 0, which means the SDK controls it.

  • forceStrictKeyFrameInterval: Whether to force the encoder to strictly follow the set keyframe interval. The default is false.

  • mirrorMode: 0

  • orientationMode: 0

  • rotation: 0

  • codecType: AliRtcVideoCodecTypeDefault

  • encoderType: AliRtcVideoEncodeCodecTypeDefault

  • seiForceFrontIFrame: -1

  • enableDynamicEncode: -1

  • disableDipenseResolutionChange: -1

  • enableDowngrade: -1

  • enableH264BFrame: -1

  • enableHevcBFrame: -1

A value of -1 indicates using the SDK's internal default settings.

setVideoDecoderConfiguration

Sets the video decoding properties.

    public abstract void setVideoDecoderConfiguration(AliRtcVideoDecoderConfiguration config);

This method sets the video parameters for the video stream decoding properties.

When to call

We recommend calling this method before joining a channel.

Parameters

Name

Type

Description

config

AliRtcVideoDecoderConfiguration

Predefined decoding properties. Default values:

  • codecType: AliRtcVideoCodecTypeDefault. Decoding type, including software decoding, hardware decoding, and hardware texture decoding.

  • enableDecoderBframe: -1. Whether to use B-frames. If enabled, the decoder will have a buffer queue, increasing latency. If the sender has enabled B-frames, you must enable this option to decode correctly.

  • textureBindContext: -1. Whether to support texture decoding context binding.

A value of -1 indicates using the SDK's internal default settings.

switchCamera

Switches between the front and rear cameras. The front camera is used by default.

public abstract int switchCamera();

This method switches between the front and rear cameras. The front camera is used by default. You can dynamically switch cameras during the application's runtime based on the available cameras, without restarting the video stream or reconfiguring the video source.

When to call

Call this method after the camera has been successfully turned on.

Limits

This is available only on Android and iOS.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getCurrentCameraDirection

Gets the current camera direction.

public abstract AliRTCCameraDirection getCurrentCameraDirection();

Return value

  • Returns CAMERA_REAR(0) for the rear camera.

  • Returns CAMERA_FRONT(1) for the front camera.

  • Returns CAMERA_INVALID(-1) for invalid.

Note

Call this method after the camera is turned on. Otherwise, it will return CAMERA_INVALID(-1).

startPreview

Starts the local preview.

public abstract int startPreview();

This method starts the local video preview and automatically turns on the camera. To stop the local preview, call the stopPreview method.

Note

Calling leaveChannel to leave a channel automatically stops the local preview. If you are not publishing a camera stream, the camera is automatically turned off.

When to call

  • Before calling this method, you need to set the view for the local preview by calling setLocalViewConfig. Otherwise, the preview will not be displayed, but this will not affect publishing.

  • If needed, you can call this method to start the preview before joining a channel with joinChannel. The camera will be turned on automatically.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

stopPreview

Stops the local preview.

public abstract int stopPreview();

This method closes the local video preview and turns off the camera. After stopping the preview, the local end will remain on the last frame, which does not affect publishing.

Note

Calling leaveChannel to leave a channel automatically stops the local preview. If you are not publishing a camera stream, the camera is automatically turned off.

When to call

To close the preview after starting it, you can call this method.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

setCameraZoom

Sets the camera zoom ratio.

public abstract int setCameraZoom(float zoom);

Sets the zoom ratio of the camera.

Limits

Only iOS and Android provide this interface.

When to call

This setting is effective only after the camera is turned on. The zoom is reset each time the camera is restarted.

Parameters

Parameter

Type

Description

zoom

float

Camera zoom ratio. The range is from 1 to the maximum zoom value supported by the camera. You can obtain the maximum zoom ratio supported by the current device by calling GetCameraMaxZoomFactor.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed.

GetCameraMaxZoomFactor

Gets the maximum zoom ratio supported by the camera.

public abstract float GetCameraMaxZoomFactor();

Return value

The maximum zoom ratio supported by the device's camera.

GetCurrentZoom

Gets the current camera zoom ratio setting.

public abstract float GetCurrentZoom();

Return value

The current zoom ratio of the device's camera.

SetExposure

Sets the camera exposure.

public abstract int SetExposure(float exposure);

When the ambient light is insufficient or too bright, it affects the quality of the video capture. To achieve better video quality, you can use this method to adjust the exposure of the camera in use. You can obtain the exposure range supported by the current device by calling GetMinExposure and GetMaxExposure.

Parameters

Parameter

Type

Description

exposure

float

The camera's exposure. The default value is 0, which means using the camera's default exposure. The larger the value, the greater the exposure. If the video image is overexposed, you can lower the exposure coefficient. If the video image is underexposed, causing loss of detail in dark areas, you can increase the exposure coefficient. If the passed exposure is outside the supported range of the device, the SDK will adjust it automatically.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed.

GetCurrentExposure

Gets the camera exposure.

public abstract float GetCurrentExposure();

Gets the exposure setting of the currently used camera.

Return value

The current camera exposure.

GetMinExposure

Gets the minimum exposure supported by the camera.

public abstract float GetMinExposure();

Return value

The minimum camera exposure.

GetMaxExposure

Gets the maximum exposure supported by the camera.

public abstract float GetMaxExposure();

Return value

The maximum camera exposure.

setCameraFlash

Sets the camera flash on or off.

public abstract int setCameraFlash(boolean flash);

Turns the flash on or off.

Note

Generally, only the rear camera has a flash function.

Limits

Only iOS and Android provide this interface.

Parameters

Parameter

Type

Description

flash

boolean

Specifies whether to turn on the flash.

  • true: Turn on the flash.

  • false: Turn off the flash.

Return value

  • 0: Success.

  • Non-zero: Failure.

isCameraFocusPointSupported

Checks whether the current device supports manual focus.

public abstract boolean isCameraFocusPointSupported();

Checks whether the current camera can set a focus point to support the manual focus feature.

Limits

Only iOS and Android provide this interface.

Return value

  • true: The device supports the manual focus feature.

  • false: The device does not support the manual focus feature.

isCameraExposurePointSupported

Checks whether setting the camera exposure point is supported.

public abstract boolean isCameraExposurePointSupported();

Checks whether the current device supports setting an exposure point.

Limits

Only iOS and Android provide this interface.

Return value

  • true: Setting the camera exposure point is supported.

  • false: Setting the camera exposure point is not supported.

setCameraFocusPoint

Sets the manual focus point for the camera.

public abstract int setCameraFocusPoint(float x, float y);

Sets the focus point of the current camera. After you call this method, the camera performs a one-time exposure adjustment on the set point and then maintains this focus value. Before you call this method, we recommend that you call isCameraFocusPointSupported to check whether the device supports the manual focus feature.

Limits

Only iOS and Android provide this interface.

Parameters

Parameter

Type

Description

x

float

The x-axis coordinate value.

y

float

The y-axis coordinate value.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed.

setCameraExposurePoint

Sets the camera exposure point.

public abstract int setCameraExposurePoint(float x, float y);

Sets the camera exposure point. After this method is called, the camera performs a one-time exposure adjustment on the set point and maintains this exposure value. Before calling this method, we recommend calling isCameraExposurePointSupported to check if the device supports the manual focus feature.

Limits

Only iOS and Android provide this interface.

Parameters

Parameter

Type

Description

x

float

The x-axis coordinate value.

y

float

The y-axis coordinate value.

Return value

  • 0: The method call succeeded.

  • Non-zero: The method call failed.

isCameraAutoFocusFaceModeSupported

Checks whether camera auto face focus is supported.

public abstract boolean isCameraAutoFocusFaceModeSupported();

Checks whether camera auto face focus is supported.

When to call

This is effective only after the camera is turned on. If the camera is not on when you call this, it returns false by default. If the camera is on and supports both facial recognition and focus functions, it returns true.

Limits

Only iOS and Android provide this interface.

Return value

  • true: Auto face focus is supported.

  • false: Auto face focus is not supported.

setCameraAutoFocusFaceModeEnabled

Sets camera face focus.

public abstract boolean setCameraAutoFocusFaceModeEnabled(boolean enable);

Call this method to set the camera to focus on faces in real time. Before calling this method, call isCameraAutoFocusFaceModeSupported to verify that the device supports this feature.

Limits

Only iOS and Android provide this interface.

Parameters

Parameter

Type

Description

enable

boolean

Enables or disables the camera face focus feature.

  • true: Enable.

  • false: Disable.

Return value

  • true: The call succeeded.

  • false: The call failed.

setVideoMirrorMode

Sets the video mirroring capability for preview and ingest.

public abstract int setVideoMirrorMode(AliRtcVideoPipelineMirrorMode mirrorMode);

Sets whether to enable mirror mode for the local preview video and the published video stream.

Note

This method has a higher priority than setLocalViewConfig&setVideoEncoderConfiguration. To set the video mirror mode, we recommend calling this method.

When to call

You can dynamically set this method before and after joining a channel. The SDK records the status and performs the video operation when it can operate on the preview and encoding (publishing).

Limits

This method overlaps with the mirrorMode in setLocalViewConfig&setVideoEncoderConfiguration. We recommend using only one method.

Parameters

Parameter

Type

Description

mirrorMode

AliRtcVideoPipelineMirrorMode

Sets the mirror mode.

Return value

  • 0: Success.

  • <0: Failure.

    • AliRtcErrInner: Internal SDK error. Check if the SDK instance was created successfully.

setCapturePipelineScaleMode

Sets the video capture scaling time.

public abstract void setCapturePipelineScaleMode(AliRtcCapturePipelineScaleMode mode);

Sets whether video data capture scaling occurs immediately upon capture or only during encoding. For example, when the capture resolution and encoding resolution are inconsistent, you can set the scaling time to determine whether the preview data and the published data are consistent.

When to call

Call this method before you turn on the camera, for example, before you start a preview with startPreview or join a channel with joinChannel.

Parameters

Parameter

Type

Description

mode

AliRtcCapturePipelineScaleMode

The mode that controls the capture scaling time. The default is to scale immediately upon capture.

Return value

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

Enables an external video input source. Valid values:

  • true: Enable.

  • false (default): Disable.

useTexture

boolean

Specifies whether to use texture mode. Valid values:

  • true: Use.

  • false (default): Do not use.

type

AliRtcVideoTrack

Video stream type.

renderMode

AliRtcRenderMode

Rendering mode.

pushExternalVideoFrame

Inputs video data.

public abstract int pushExternalVideoFrame(AliRtcRawDataFrame aliRawDataFrame,AliRtcVideoTrack streameType);

Parameters

Parameter

Type

Description

aliRawDataFrame

AliRtcRawDataFrame

Frame data.

streameType

AliRtcVideoTrack

Video stream type.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

startPublishLiveStream

Starts bypass live streaming.

public abstract int startPublishLiveStream(String streamUrl,AliRtcLiveTranscodingParam transcodingParam);

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

transcodingParam

AliRtcLiveTranscodingParam

Ingest parameters.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

updatePublishLiveStream

Updates bypass live streaming parameters.

public abstract int updatePublishLiveStream(String streamUrl,AliRtcLiveTranscodingParam transcodingParam);

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

transcodingParam

AliRtcLiveTranscodingParam

Ingest parameters.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

stopPublishLiveStream

Stops bypass live streaming.

public abstract int stopPublishLiveStream(String streamUrl);

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

Return value

0 indicates the method call was successful. Any other value indicates a failure.

getPublishLiveStreamState

Gets the bypass live streaming status.

public abstract AliRtcEngine.AliRtcLiveTranscodingState getPublishLiveStreamState(String streamUrl);

Parameters

Parameter

Type

Description

streamUrl

String

Bypass live stream ingest URL.

Return value

Returns the bypass live streaming status.

startNetworkQualityProbeTest

Starts a network quality probe.

public abstract int startNetworkQualityProbeTest(AlirtcNetworkQualityProbeConfig config);

Parameters

Parameter

Type

Description

config

AlirtcNetworkQualityProbeConfig

Probe configuration parameters.

Return value

0: Success. Other: Failure.

stopNetworkQualityProbeTest

Stops a network quality probe.

public abstract int stopNetworkQualityProbeTest();

Return value

0: Success. Other: Failure.

sendMediaExtensionMsg

Sends a media extension message.

public abstract int sendMediaExtensionMsg(byte[]message, int repeatCount, int delay, boolean isKeyFrame);

The SDK provides the functionality to send and receive media extension messages. This method sends media extension messages using the SEI extension protocol. Receivers can obtain the messages by listening to onMediaExtensionMsgReceived.

Common scenarios include the following:

  • Using media extension messages to transmit timestamps to calculate end-to-end network latency or to synchronize data with other business services.

  • Using media extension messages to transmit descriptive information. Currently, up to 4 KB of data can be transmitted, which can be used to transfer small amounts of data. We recommend using JSON or plain strings.

When to call

Call this after you start publishing a stream.

Limits

When using media extension messages, the audio and video data channels are reused. Therefore, you must control the sending frequency and message data length. The limits are as follows:

  • You can send a maximum of fps messages per second, as set in the profile. SEI information is transmitted in the H.264/H.265 stream, and extension information can only be attached when there is video frame encoding.

  • To avoid affecting the quality of media data transmission, the custom message body is limited to 4 KB. It can be used to transmit small amounts of information.

  • The repeatCount parameter in the sendMediaExtensionMsg function is the redundancy of the custom message. If it is greater than 1, the message will be sent multiple times.

  • To prevent message loss due to network packet loss, other people in the channel will also receive the same message multiple times and need to remove duplicates.

  • When custom messages are sent, subscribers in the channel will also receive them during bypass live streaming.

  • Only one MediaExtensionMsg can be transmitted at a time. If you call sendMediaExtensionMsg multiple times, the new data will overwrite the previous data.

Related callbacks

After the publishing end sends a media extension message, the pulling end can get the message by listening to the onMediaExtensionMsgReceived callback.

Parameters

Parameter

Type

Description

message

byte[]

Media extension message. The maximum length is 4 KB.

repeatCount

int

Number of repetitions. This represents message redundancy to prevent message loss due to network packet loss. -1 means infinite transmission.

delay

int

Delay in milliseconds. The minimum time in milliseconds to send the extension message after the API is called.

isKeyFrame

boolean

Specifies whether to use the extension message only for keyframes. true means the extension message is attached only to keyframes.

Return value

  • 0: Success.

  • <0: Failure. An error code is returned.

    • ERR_INNER(-1): Internal SDK error. The SDK may not have been initialized or was called after being destroyed.

sendMediaExtensionMsgEx

Sends a media extension message.

public abstract int sendMediaExtensionMsgEx(byte[]message, int repeatCount, int delay, boolean isKeyFrame, int payloadType);

The SDK provides features to send and receive media extension messages. This method sends a media extension message using the SEI extension protocol. The receiver can obtain the message by listening to onMediaExtensionMsgReceived. When payloadType is 5, this is equivalent to using the sendMediaExtensionMsg method.

Common scenarios include the following:

  • Using media extension messages to transmit timestamps to calculate end-to-end network latency or to synchronize data with other business services.

  • Using media extension messages to transmit descriptive information. Currently, up to 4 KB of data can be transmitted, which can be used to transfer small amounts of data. We recommend using JSON or plain strings.

When to call

Call this after you start publishing a stream.

Limits

When using media extension messages, the audio and video data channels are reused. Therefore, you must control the sending frequency and message data length. The limits are as follows:

  • You can send a maximum of fps messages per second, as set in the profile. SEI information is transmitted in the H.264/H.265 stream, and extension information can only be attached when there is video frame encoding.

  • To avoid affecting the quality of media data transmission, the custom message body is limited to 4 KB. It can be used to transmit small amounts of information.

  • The repeatCount parameter in the sendMediaExtensionMsg function is the redundancy of the custom message. If it is greater than 1, the message will be sent multiple times.

  • To prevent message loss due to network packet loss, other people in the channel will also receive the same message multiple times and need to remove duplicates.

  • When custom messages are sent, subscribers in the channel will also receive them during bypass live streaming.

  • Only one MediaExtensionMsg can be transmitted at a time. If you call sendMediaExtensionMsg multiple times, the new data will overwrite the previous data.

Parameters

Parameter

Type

Description

message

byte[]

Media extension message. The maximum length is 4 KB.

repeatCount

int

Number of repetitions. This represents message redundancy to prevent message loss due to network packet loss. -1 means infinite transmission.

delay

int

Delay in milliseconds. The minimum time in milliseconds to send the extension message after the API is called.

isKeyFrame

boolean

Specifies whether to use the extension message only for keyframes. true means the extension message is attached only to keyframes.

payloadType

int

The range is [5, 100..254]. payloadType=5 is equivalent to using the sendMediaExtensionMsg method.

Return value

  • 0: Success.

  • <0: Failure. An error code is returned.

    • ERR_INNER(-1): Internal SDK error. The SDK may not have been initialized or was called after being destroyed.

onConnectionStatusChange

Callback for network connection status changes. You need to handle this callback.

public void onConnectionStatusChange(AliRtcEngine.AliRtcConnectionStatus status,
 AliRtcEngine.AliRtcConnectionStatusChangeReason reason);

Parameters

Parameter

Type

Description

status

AliRtcConnectionStatus

Current network connection status.

reason

AliRtcConnectionStatusChangeReason

Reason for the network connection status change.

OnLocalDeviceException

Callback for local device exceptions. You need to handle this callback.

public void OnLocalDeviceException(AliRtcEngine.AliRtcEngineLocalDeviceType deviceType, AliRtcEngine.AliRtcEngineLocalDeviceExceptionType exceptionType, String msg)

Parameters

Parameter

Type

Description

deviceType

AliRtcEngineLocalDeviceType

Device type

exceptionType

AliRtcEngineLocalDeviceExceptionType

Device exception type

msg

String

Information carried with the exception.

onAuthInfoWillExpire

Notification that user authentication information is about to expire. Authentication expires 30 seconds after this callback is received. You need to handle this callback.

public void onAuthInfoWillExpire();

This callback indicates that the user's authentication information is about to expire. Authentication expires 30 seconds after this callback is received. You need to get a new token and then update the authentication information in one of the following ways:

  • 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 call joinChannel to rejoin the channel.

When triggered

The SDK triggers this callback 30 seconds before the user's authentication information expires. You should update the authentication information promptly after receiving this callback.

onAuthInfoExpired

The server returns that the information has expired when the user calls an interface that requires authentication.

public void onAuthInfoExpired();

This callback indicates that the user's authentication information has expired. If you want to continue in the session, you need to generate a new token on the server and then update the authentication information by:

  • Call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="c3b0cf2f19dgm">leaveChannel</a> to leave the current channel, and then call joinChannel to rejoin the channel.

When triggered

This callback is triggered when the user's authentication information expires.

onJoinChannelResult

Callback for the result of joining a channel.

public void onJoinChannelResult(int result, String channel, String userId, int elapsed);

Parameters

Parameter

Type

Description

result

int

The result of joining the channel. A return value of 0 indicates success. An error code is returned on failure. For more information, see Error code list. The following are some common error codes:

  • ERR_JOIN_BAD_APPID: The AppId does not exist.

  • ERR_JOIN_INVALID_APPID: The AppId has expired.

  • ERR_JOIN_BAD_CHANNEL: The channel does not exist.

  • ERR_JOIN_INVALID_CHANNEL: The channel has expired.

  • ERR_JOIN_BAD_TOKEN: The token does not exist.

  • ERR_JOIN_TIMEOUT: Timed out when joining the channel.

  • ERR_JOIN_BAD_PARAM: Incorrect parameter for joining the channel.

  • ERR_JOIN_FAILED: Failed to join the channel.

  • ERR_JOIN_CONFIG_INVALID: Invalid join parameter, such as an empty token.

channel

String

Channel ID.

userId

String

User ID.

elapsed

int

Time taken to join the channel, in milliseconds.

onLeaveChannelResult

Callback for the result of leaving a channel.

public void onLeaveChannelResult(int result, AliRtcEngine.AliRtcStats stats);

Trigger condition

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> to leave the channel, this callback is triggered and returns the result of leaving the channel and the statistics of this channel session.

Note

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. 0 is returned for success. An error code is returned for failure.

stats

AliRtcStats

A summary of data statistics for the session in this channel.

onRemoteUserOffLineNotify

Callback for when a remote user goes offline.

public void onRemoteUserOffLineNotify(String uid, AliRtcUserOfflineReason reason);

This callback notifies the local user that a remote user has left the channel for various reasons. This method is triggered when a remote user goes offline.

Trigger condition

  • The callback is triggered when a remote user actively leaves the channel.

  • 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 to set the role to AliRTCSdkLive), a callback is triggered.

  • The callback is triggered when no data is received from the remote streamer for a long time and the user is considered to have dropped.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

reason

AliRtcUserOfflineReason

The reason the user went offline.

onRemoteUserOnLineNotify

Callback for 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.

Trigger condition

  • A remote user successfully joins the channel.

  • After the current user joins the channel, they receive a join callback for users already in the channel, which is used to display previously joined users.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

elapsed

int

The time it took for the user to join the channel, in milliseconds.

onRemoteTrackAvailableNotify

Callback for when a remote user's audio or video stream changes.

public void onRemoteTrackAvailableNotify(String uid, AliRtcAudioTrack audioTrack,
 AliRtcVideoTrack videoTrack);

This callback is triggered when a remote user's publishing status changes. With this callback, you can know in real time whether a remote user is publishing audio and video streams and display or hide the remote user's audio and video information on the interface accordingly.

Note

This callback returns the remote user's publishing status. To know which stream went offline in this change, record the status changes before and after the callback.

Trigger condition

This callback is triggered in the following scenarios:

  • When a remote user changes from not publishing to publishing (including audio and video).

  • When a remote user changes from publishing to not publishing (including audio and video).

  • In interactive mode, when a remote user calls setClientRole to switch from viewer to streamer and also sets publishing, this callback is triggered.

Take video as an example. Assume the remote user is set not to publish. This callback is not triggered.

  • If a remote user starts pushing a camera stream (Stream ingest status: no video stream -> only camera stream), the callback on the local client returns AliRtcVideoTrackCamera to indicate that the remote user's camera stream is available.

  • If the remote user also pushes a screen sharing stream (Stream ingest status: Only camera stream -> Camera stream and screen sharing stream), the local end receives the AliRtcVideoTrackBoth callback, indicating that both the remote user's camera and screen sharing streams are available.

  • If the remote user stops pushing the camera stream and keeps only the screen sharing stream (Stream ingest state: Camera and screen sharing streams -> Screen sharing stream only), the local client receives the AliRtcVideoTrackScreen callback, indicating that only the screen sharing stream is currently available.

  • If the remote user also stops pushing the screen sharing stream (Stream ingest status: Pushing only the screen sharing stream -> Not pushing a video stream), the local client receives the AliRtcVideoTrackNo callback, which indicates that no video stream is currently active.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

audioTrack

AliRtcAudioTrack

The audio stream after the remote user's change.

videoTrack

AliRtcVideoTrack

The video stream after the remote user's change.

onBye

Callback for when the user is kicked from the server or the channel is closed.

public void onBye(int code);

When a user is disconnected for any reason or the meeting ends, this callback is triggered, allowing you to use the callback parameter code to determine the reason for the disconnection and take appropriate action.

Trigger condition

  • The current user is kicked from the server.

  • The session ends (the server actively removes the channel).

  • Passive departure. The client needs to try to restore the session or reconnect.

Parameters

Parameter

Type

Description

code

int

The onBye type. For more information, see AliRtcOnByeType.

onAudioPublishStateChanged

Callback for audio publishing state changes.

public void onAudioPublishStateChanged(AliRtcEngine.AliRtcPublishState oldState , 
 AliRtcEngine.AliRtcPublishState newState,
 int elapseSinceLastState, String channel);

This callback listens for changes in the local user's audio publishing status.

Trigger condition

When the user's audio publishing status changes, for example:

  • Publishing is stopped.

  • Call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#84f350f904s98" id="e6c8edfc45xbw">setClientRole</a> to switch to the viewer role.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

Previous publishing status.

newState

AliRtcPublishState

Current publishing status.

elapseSinceLastState

int

Time interval since the last state change, in milliseconds.

channel

String

Current channel ID.

onAudioSubscribeStateChanged

Callback for audio subscription state changes.

public void onAudioSubscribeStateChanged(String uid,
 AliRtcEngine.AliRtcSubscribeState oldState,
 AliRtcEngine.AliRtcSubscribeState newState,
 int elapseSinceLastState, String channel);

This callback notifies the local user when a remote user's audio stream subscription status changes. Through this callback, you can learn about the subscription status change of a specific remote user's audio stream and the time interval from the previous state to the current state.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

oldState

AliRtcSubscribeState

Previous subscription status.

newState

AliRtcSubscribeState

Current subscription status.

elapseSinceLastState

int

Time interval since the last state change, in milliseconds.

channel

String

Current channel ID.

onUserAudioMuted

Notification that the remote user has stopped sending audio data.

public void onUserAudioMuted(String uid ,boolean isMute);

Parameters

Parameter

Type

Description

uid

String

The user who executed muteAudio.

isMute

boolean

Specifies whether the user is muted. Valid values:

  • true: Muted.

  • false: Not muted.

onUserAudioInterruptedBegin

Notification that a user's audio has been interrupted.

public void onUserAudioInterruptedBegin(String uid);

Parameters

Parameter

Type

Description

uid

String

The user whose audio was interrupted.

onUserAudioInterruptedEnded

Notification that a user's audio interruption has ended.

public void onUserAudioInterruptedEnded(String uid);

Parameters

Parameter

Type

Description

uid

String

The user whose audio was interrupted.

onVideoPublishStateChanged

Callback for video publishing state changes.

public void onVideoPublishStateChanged(AliRtcEngine.AliRtcPublishState oldState , 
 AliRtcEngine.AliRtcPublishState newState, 
 int elapseSinceLastState, String channel);

This callback listens for changes in the local user's video publishing status.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

Previous publishing status.

newState

AliRtcPublishState

Current publishing status.

elapseSinceLastState

int

Time interval since the last state change, in milliseconds.

channel

String

Current channel ID.

onVideoSubscribeStateChanged

Callback for camera stream subscription state changes.

public void onVideoSubscribeStateChanged(String uid,
 AliRtcEngine.AliRtcSubscribeState oldState,
 AliRtcEngine.AliRtcSubscribeState newState,
 int elapseSinceLastState, String channel);

This callback notifies the local user when a remote user's camera stream subscription status changes. Through this callback, you can learn about the subscription status change of a specific remote user's camera stream and the time interval from the previous state to the current state.

Related callbacks

Video streams mainly consist of camera streams and screen sharing streams. This interface is for changes in the subscription state of a camera stream. The related callback interface for a screen sharing stream is onScreenShareSubscribeStateChanged.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

oldState

AliRtcSubscribeState

Previous subscription status.

newState

AliRtcSubscribeState

Current subscription status.

elapseSinceLastState

int

Time interval since the last state change.

channel

String

Current channel ID.

onUserVideoMuted

Notification that the remote user is sending black video frames.

public void onUserVideoMuted(String uid, boolean isMute);

Parameters

Parameter

Type

Description

uid

String

The user who executed enableLocalVideo.

isMute

boolean

Specifies whether to send black frames. Valid values:

  • true: Publish black frames.

  • false: Publish normally.

onUserVideoEnabled

Notification that the remote user has disabled camera stream collection.

public void onUserVideoEnabled(String uid, boolean isMute);

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

isMute

boolean

Specifies whether to enable camera stream collection. Valid values:

  • true: Enable camera stream collection.

  • false: Disable camera stream collection.

onUserWillResignActive

The remote user's application has moved to the background.

public void onUserWillResignActive(String uid);

Parameters

Parameter

Type

Description

uid

String

User ID.

onUserWillBecomeActive

The remote user's application has returned to the foreground.

public void onUserWillBecomeActive(String uid);

Parameters

Parameter

Type

Description

uid

String

User ID.

onAliRtcStats

Callback for current session statistics. The SDK triggers this callback every two seconds.

public void onAliRtcStats(AliRtcEngine.AliRtcStats stats);

Parameters

Parameter

Type

Description

stats

AliRtcStats

Session statistics.

onAudioEffectFinished

Callback for when local sound effect playback finishes.

void OnAudioEffectFinished(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file by the user.

onAudioFileInfo

Callback for audio file information.

public void  onAudioFileInfo(AliRtcEngine.AliRtcAudioFileInfo info, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);

When you call getAudioFileInfo to obtain audio file information, this callback is triggered to show you the audio file's duration and other information or error messages.

Parameters

Parameter

Type

Description

info

AliRtcEngine.AliRtcAudioFileInfo

Information about the audio file, including the file path and duration.

errorCode

AliRtcEngine.AliRtcAudioAccompanyErrorCode

Audio accompaniment error code, mainly for file open and decode errors.

onMediaExtensionMsgReceived

Callback for receiving a media extension message.

public void onMediaExtensionMsgReceived(String uid, int payloadType, byte[]message);

When one end sends a message through sendMediaExtensionMsg, other ends receive the data through this callback.

Parameters

Parameter

Type

Description

uid

String

User ID of the media message sender.

payloadType

int

Payload type. sendMediaExtensionMsg returns 5. sendMediaExtensionMsgEx returns the specific type.

message

byte[]

Media extension message.

onFirstRemoteVideoFrameDrawn

This message is triggered when the first video frame of a remote user is displayed.

public void onFirstRemoteVideoFrameDrawn(String uid,AliRtcVideoTrack videoTrack, int width, int height, int elapsed);

This is the callback for the first rendered frame of a remote video. It is triggered when the local user successfully receives and renders the first video frame from a remote user. This callback helps you monitor the setup time of the remote video link, evaluate network and device performance, and optimize the user experience.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

videoTrack

AliRtcVideoTrack

Received video stream type.

width

int

Pulled video width.

height

int

Pulled video height.

elapsed

int

The total delay from when the local user joins the channel until the first frame of the pulled video is displayed (in milliseconds).

onFirstLocalVideoFrameDrawn

This message is triggered when the first video frame is displayed in the preview.

public void onFirstLocalVideoFrameDrawn(int width, int height, int elapsed);

This is the callback for the first frame displayed in the local video preview. It is triggered when the first local video frame is rendered after the local user turns on the camera. This callback helps you monitor the local video preview setup speed, evaluate device performance, and optimize the user experience (such as showing a "Camera ready" message or adjusting the preview layout).

Parameters

Parameter

Type

Description

width

int

Local preview video width.

height

int

Local preview video height.

elapsed

int

The total delay from when the local user joins the channel until the first frame of the local preview is displayed (in milliseconds).

onFirstVideoFrameReceived

Callback for receiving the first video frame from a remote user.

public void onFirstVideoFrameReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost);

This is the callback for receiving the first frame of a remote video. It is triggered when the local user successfully receives the first video frame from a remote user. This callback helps you monitor the video link setup time, evaluate network quality, and optimize the user experience (such as showing a "Video ready" message or adjusting playback logic).

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

videoTrack

AliRtcVideoTrack

Received video stream type.

timeCost

int

Sending time cost. The time from joining the channel to sending the first video packet (in milliseconds).

onFirstVideoPacketSent

Callback for the first video packet sent.

public void onFirstVideoPacketSent(String uid, AliRtcVideoTrack videoTrack, int timeCost);

This is the callback for the first local video packet sent. It is triggered when the local user successfully sends the first video data packet. This callback helps you monitor the video sending link setup speed, evaluate local device performance, and optimize the user experience (such as showing a "Video sent" message or adjusting the collection policy).

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

videoTrack

AliRtcVideoTrack

Received video stream type.

timeCost

int

Sending time cost. The time from joining the channel to sending the first video packet (in milliseconds).

onFirstAudioPacketSent

Callback for the first audio packet sent.

public void onFirstAudioPacketSent(String uid, AliRtcAudioTrack track, int timeCost);

This is the callback for the first local audio packet sent. It is triggered when the local user successfully sends the first audio data packet. This callback helps you monitor the audio sending link setup speed, evaluate local device and system performance, and optimize the user experience.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

track

AliRtcAudioTrack

Received audio stream type.

timeCost

int

Sending time cost. The time from joining the channel to sending the first audio packet (in milliseconds).

onFirstVideoPacketReceived

Callback for the first video packet received.

public void onFirstVideoPacketReceived(String uid, AliRtcVideoTrack videoTrack, int timeCost)

This is the callback for the first remote video packet received. It is triggered when the local user receives the first video data packet from a remote user. You can use this callback to monitor the video link setup speed or update the UI components of the playback stream.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

videoTrack

AliRtcVideoTrack

Received video stream type.

timeCost

int

The time from when the local user joins the channel to when the first video packet is received (in milliseconds).

onFirstAudioPacketReceived

Callback for the first audio packet received.

public void onFirstAudioPacketReceived(String uid, AliRtcAudioTrack track, int timeCost)

This is the callback for the first remote audio packet received. It is triggered when the local user receives the first audio data packet from a remote user. This callback helps you monitor the audio link setup speed, evaluate network quality, and optimize the user experience (such as showing an "Audio connected" message or adjusting the playback policy).

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

track

AliRtcAudioTrack

Received audio stream type.

timeCost

int

The time from when the local user joins the channel to when the first audio packet is received (in milliseconds).

onFirstRemoteAudioDecoded

Callback for the first decoded remote audio frame.

public void onFirstRemoteAudioDecoded(String uid, AliRtcAudioTrack track, int elapsed)

This is the callback for the first decoded frame of a pulled remote audio stream. It notifies you that the remote user's audio stream has been successfully decoded and can be played normally. You can use this callback to measure the first frame time or update the UI components of the playback stream.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

track

AliRtcAudioTrack

Received audio stream type.

elapsed

int

The delay from when the local user joins the channel to when the first audio frame is decoded (in milliseconds).

onAudioAccompanyStateChanged

Callback for local accompaniment playback state.

public void onAudioAccompanyStateChanged(AliRtcEngine.AliRtcAudioAccompanyStateCode playState, AliRtcEngine.AliRtcAudioAccompanyErrorCode errorCode);

This is the callback for local accompaniment playback state changes. It notifies you in real time of the current playback state of the accompaniment (such as start, pause, end) and any possible error codes. You can use this callback to monitor playback progress, handle exceptions, and update the user interface.

Parameters

Parameter

Type

Description

playState

AliRtcEngine.AliRtcAudioAccompanyStateCode

Accompaniment playback state.

errorCode

AliRtcEngine.AliRtcAudioAccompanyErrorCode

Playback error code, mainly for file open and decode errors.

onRemoteAudioAccompanyStarted

Callback for when a remote user's accompaniment starts playing.

public void onRemoteAudioAccompanyStarted(String uid);

This is the callback for when a remote user's audio accompaniment (such as background music) starts playing. It notifies the local application. You can use this callback to execute initialization logic (such as updating the UI, adjusting volume, or notifying other users).

Parameters

Parameter

Type

Description

uid

String

The remote user ID whose accompaniment has started playing.

onRemoteAudioAccompanyFinished

Callback for when a remote user's accompaniment finishes playing.

public void onRemoteAudioAccompanyFinished(String uid);

This is the callback for when a remote user's audio accompaniment (such as background music or sound effects) finishes playing. It notifies the local application. You can use this callback to execute subsequent logic (such as notifying users or updating status).

Parameters

Parameter

Type

Description

uid

String

The remote user ID whose accompaniment has finished playing.

onVideoResolutionChanged

Remote video resolution changes.

public void onVideoResolutionChanged(String uid,AliRtcVideoTrack videoTrack, int width, int height);

This is the notification callback for remote video resolution changes. It is triggered when a remote user's video stream resolution changes (such as switching cameras, adjusting definition, or resolution dropping 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

The remote user ID whose resolution has changed.

videoTrack

AliRtcVideoTrack

Video stream type, such as camera stream or screen stream.

width

int

New video resolution width.

height

int

New video resolution height.

onRtcLocalVideoStats

Data statistics for the published local video stream.

public void onRtcLocalVideoStats(AliRtcEngine.AliRtcLocalVideoStats aliRtcStats);

This is the callback for local video stream data statistics. It is used to get the real-time encoding and transmission status of the local video (such as bitrate and frame rate). You can use this callback to monitor video quality, diagnose performance issues, or dynamically adjust encoding parameters.

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcLocalVideoStats

Statistics for the locally published video, including publishing bitrate, frame rate, and other information. For more information, see AliRtcLocalVideoStats.

onRtcRemoteVideoStats

Data statistics for the subscribed remote video stream.

public void onRtcRemoteVideoStats(AliRtcEngine.AliRtcRemoteVideoStats aliRtcStats);

This is the callback for pulled remote video stream data statistics. It is used to get the real-time encoding and transmission status of the remote video (such as bitrate, frame rate, resolution, latency, and stuttering). You can use this callback to monitor video quality, diagnose performance issues, or dynamically adjust decoding parameters.

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcRemoteVideoStats

Statistics for the pulled remote video, including remote user ID, video resolution, frame rate, number of stutters, and other information. For more information, see AliRtcRemoteVideoStats.

onRtcRemoteAudioStats

Data statistics for the subscribed remote audio stream.

public void onRtcRemoteAudioStats(AliRtcEngine.AliRtcRemoteAudioStats aliRtcStats);

This is the callback for subscribed remote audio stream data statistics. It is used to get the real-time audio quality status of remote users (such as audio quality, packet loss rate, and latency). You can use this callback to monitor the stability of the remote audio link, diagnose network issues, and dynamically adjust playback policies (such as enabling noise reduction or prompting users to optimize their network).

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcRemoteAudioStats

Statistics for the pulled remote audio, including remote user ID, audio quality, packet loss rate, number of stutters, latency, and other information. For more information, see AliRtcRemoteAudioStats.

onRtcLocalAudioStats

Data statistics for the published local audio stream.

public void onRtcLocalAudioStats(AliRtcEngine.AliRtcLocalAudioStats aliRtcStats);

This is the callback for local audio publishing data statistics. It is used to get the real-time encoding and transmission status of the local audio (such as bitrate, sample rate, number of 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 (such as reducing the bitrate).

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcLocalAudioStats

Statistics for the locally published audio, including audio stream type, sending bitrate, sending sample rate, and number of channels. For more information, see AliRtcLocalAudioStats.

onAudioFocusChange

Callback for audio focus changes (Android only).

public void onAudioFocusChange(int focusChange);

Notification of audio focus change results. The SDK automatically requests audio focus by default. If the audio focus is used externally again, you need to request it again in the callback received from the SDK.

Notification time

Triggered when the audio output device status changes (such as inserting/unplugging headphones, switching Bluetooth devices, or switching between earpiece/speaker).

Parameters

Parameter

Type

Description

focusChange

int

Focus status type. The value is the same as the focus type definition in android.media.AudioManager.

onAudioRouteChanged

Callback for audio route changes (Android and iOS only).

public void onAudioRouteChanged(AliRtcEngine.AliRtcAudioRouteType routing);

This is the notification callback for audio route changes. It is used to detect changes in the device's audio output path (such as headphone insertion or speaker switching). This callback is only for Android and iOS. You can use this callback to dynamically adjust audio output policies (such as switching microphone modes or adjusting volume).

Parameters

Parameter

Type

Description

routing

AliRtcEngine.AliRtcAudioRouteType

The currently used audio route.

onRemoteUserSubscribedDataChannel

Callback that indicates you can start sending data channel messages.

public void onRemoteUserSubscribedDataChannel(String uid);

This is the callback triggered when a remote user subscribes to the Data Channel. This callback notifies the local user that the specified remote user is ready to receive custom messages. You can then safely call sendDataChannelMsg to send data to them. This callback is a key mechanism for ensuring reliable message delivery, preventing packet loss or failure when sending messages to a user who has not yet subscribed to the Data Channel.

Note

This callback is triggered only in Real-time Conversational AI scenarios.

Parameters

Parameter

Type

Description

uid

String

Remote user ID.

onDataChannelMessage

Callback for receiving a custom data channel message.

public void onDataChannelMessage(String uid, AliRtcEngine.AliRtcDataChannelMsg msg);

The ARTC SDK provides the ability to send and receive custom messages, allowing you to send custom real-time message data while transmitting audio and video data. This callback is used to receive custom messages from the data channel. For more information, see Send and receive custom messages.

Note
  • In interactive scenarios, streamers can send and receive messages, while viewers can only receive messages.

  • This feature is disabled by default. To enable it, call setParameter with {\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}} after you create the engine.

When triggered

After the sender calls sendDataChannelMsg to send a custom message, this callback is triggered on the receiver side if the data channel feature is enabled.

Parameters

Parameter

Type

Description

uid

String

Sender's user ID.

msg

AliRtcEngine.AliRtcDataChannelMsg

The received custom message.

onAudioVolume

Audio volume, voice status, and UID of subscribed users.

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> API. After this callback is enabled, the SDK triggers it at the interval set in <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="e5e0d330423ax">enableAudioVolumeIndication</a> after you join a channel that has users ingesting streams, providing volume information of local and remote speakers.

Parameters

Parameter

Type

Description

speakers

List<AliRtcEngine.AliRtcAudioVolume>

An array of user volume information, including user uid, voice status, and volume.

  • When uid is 0, it indicates the local speaker.

  • When uid is 1, it indicates the mixed volume of all remote users.

  • Other values indicate the volume information of the specified remote user's uid.

totalVolume

int

The total volume after mixing. The range is [0, 255].

In the local user's callback, totalVolume is the volume after mixing for the local user. In the remote user's callback, totalVolume is the total volume after mixing for all speakers.

onActiveSpeaker

Callback for the current speaker.

public void OnActiveSpeaker(String uid);

After <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#dbc70a301dtjz" id="699faf2d18k2x">enableAudioVolumeIndication</a> is successfully called, the SDK continuously monitors the remote user with the loudest volume and counts the number of times that user is identified as the loudest speaker. Within the current time period, the remote user with the highest cumulative count is considered the most active user.

Trigger condition

When the number of users in the channel is greater than or equal to 2 and there is an active remote user, the SDK triggers this callback and reports the uid of the most active remote user.

  • If the most active remote user remains the same, the SDK will not trigger the onActiveSpeaker callback again.

  • If the most active remote user changes, the SDK triggers this callback again and reports the uid of the new most active remote user.

Parameters

Parameter

Type

Description

uid

String

The speaker's uid. When uid is 0, it indicates the local speaker. It returns the user ID with the loudest sound in the current time period, not the user with the loudest instantaneous sound.

OnTestAudioVolume

Pre-call test. Callback for volume information.

public void OnTestAudioVolume(int volume);

This callback provides the volume information of the local audio capture device during a pre-call test, which you can use to verify that the device is working properly. It is triggered when you call startAudioCaptureTest to perform a pre-call audio device test.

Parameters

Parameter

Type

Description

volume

int

Volume value.

onCapturedAudioFrame

Callback for raw captured audio data.

boolean onCapturedAudioFrame(AliRtcAudioFrame frame);

This callback gets the raw audio data collected by the current device. It is disabled by default. To get this audio data:

  • Enable this callback using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). The config parameter can also be used to set the sample rate, the number of sound channels, and the read/write mode for the audio data.

  • Call registerAudioFrameObserver to register the audio data receiving object.

Note

This interface supports setting the sample rate, number of channels, and read/write mode.

Limits

Do not perform any time-consuming operations in this callback function. Otherwise, sound abnormalities may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: Success.

  • false: Failure.

onProcessCapturedAudioFrame

Callback for audio data after 3A processing.

boolean onProcessCapturedAudioFrame(AliRtcAudioFrame frame);

This callback gets the audio data after 3A processing. It is disabled by default. To get this audio data:

  • Enable this callback through the audioSource in enableAudioFrameObserver(true,audioSource,config). The config parameter can also set the sample rate, the number of sound channels, and the read/write mode for the audio data.

  • Call registerAudioFrameObserver to register the audio data receiving object.

Note

This interface supports setting the sample rate, number of channels, and read/write mode.

Limits

Do not perform any time-consuming operations in this callback function. Otherwise, sound abnormalities may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: Success.

  • false: Failure.

onPublishAudioFrame

Callback for ingest audio data.

boolean onPublishAudioFrame(AliRtcAudioFrame frame);

This callback gets the published audio data. It is disabled by default. To get this audio data:

  • Enable this callback using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). Additionally, the config parameter lets you set the sample rate, the number of sound channels, and the read/write mode for the retrieved audio data.

  • Call registerAudioFrameObserver to register the audio data receiving object.

Note

This interface supports setting the sample rate and number of channels, but can only be set to read-only mode.

Limits

Do not perform any time-consuming operations in this callback function. Otherwise, sound abnormalities may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: Success.

  • false: Failure.

onPlaybackAudioFrame

Callback for playback data.

boolean onPlaybackAudioFrame(AliRtcAudioFrame frame);

This callback gets the playback audio data. It is disabled by default. To get this audio data:

  • Enable this callback through the audioSource in enableAudioFrameObserver(true,audioSource,config). The config parameter can also set the sample rate, the number of sound channels, and read/write mode for the audio data.

  • Call registerAudioFrameObserver to register the audio data receiving object.

Note

This interface supports setting the sample rate, number of channels, and read/write mode.

Limits

Do not perform any time-consuming operations in this callback function. Otherwise, sound abnormalities may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: Success.

  • false: Failure.

onRemoteUserAudioFrame

Callback for remote stream pulling data.

boolean onRemoteUserAudioFrame(String uid, AliRtcAudioFrame frame);

This callback gets the pulled remote audio data of a specified user. It is disabled by default. To get this audio data:

  • Enable this callback through the audioSource in enableAudioFrameObserver(true,audioSource,config). The config parameter can also set the sample rate, number of channels, and read/write mode for the audio data.

  • Call registerAudioFrameObserver to register the audio data receiving object.

Note

This interface does not support setting the sample rate or number of channels, but you can set the read/write mode.

Limits

Do not perform any time-consuming operations in this callback function. Otherwise, sound abnormalities may occur.

Parameters

Parameter

Type

Description

uid

String

User ID.

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: Success.

  • false: Failure.

OnDestroyCompletion

Callback for engine destruction completion.

void OnDestroyCompletion();

This callback indicates that the SDK engine instance has been destroyed and a new one can be created.

When triggered

When you call destroy[2/2], this callback is triggered after the engine is destroyed.

onTextureCreate

Callback for OpenGL context creation.

void onTextureCreate(long context);
Note

This callback is triggered when the internal OpenGL context of the SDK is created.

Trigger condition

This callback is triggered when the internal OpenGL context of the SDK is created. You can initialize related resources.

Parameters

Parameter

Type

Description

context

long

OpenGL context.

onTextureUpdate

Callback for OpenGL texture updates.

int onTextureUpdate(int textureId, int width, int height, AliRtcVideoSample videoSample);

Trigger condition

This callback is triggered after each video frame is uploaded to the OpenGL texture. When an external OpenGL texture data observer is registered, you can process the texture in this callback and return the processed texture ID.

Parameters

Parameter

Type

Description

textureId

int

OpenGL context.

width

int

Video width.

height

int

Video height.

videoSample

AliRtcVideoSample

Video frame data.

Return value

Returns a new texture ID or the old texture ID. If a value less than 0 is returned, the texture ID is considered not updated.

onTextureDestroy

void onTextureDestroy();

Trigger condition

This callback is triggered when the internal OpenGL context of the SDK is destroyed. You can clean up related resources.

onLocalVideoSample

Callback for subscribed local captured video data.

public boolean onLocalVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);

This is the callback for getting local video collection data. It is used to get the raw video frames (such as YUV data) collected by the local camera. You can use this callback to implement custom video processing logic (such as adding filters, watermarks, or transcoding) and decide whether to return the processed data to the SDK for subsequent encoding or rendering. To send the processed video to the SDK, return true.

When triggered

After you successfully call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="22a5a6bd53c77">registerVideoSampleObserver</a> to register a video data observer, a callback is triggered when the SDK captures the corresponding video frame.

Parameters

Parameter

Type

Description

sourceType

AliRtcVideoSourceType

Video source type.

videoSample

AliRtcVideoSample

Video data.

Return value

  • true: Needs to be written back to the SDK (default is to write back; must be written back when operating on AliRtcVideoSample.data).

  • false: Does not need to be written back to the SDK (used when directly operating on AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV).

onPreEncodeVideoSample

Callback for subscribed local pre-encoding video data.

public boolean onPreEncodeVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoRawData);

This is the callback for getting local pre-encoding video data. It is used to get the raw video data (such as YUV format) before the SDK encodes the video frame. You can use this callback to implement custom processing logic (such as adding watermarks, adjusting colors, or transcoding) and decide whether to return the processed data to the SDK for subsequent encoding.

Parameters

Parameter

Type

Description

sourceType

AliRtcVideoSourceType

Video stream type.

videoRawData

AliRtcVideoSample

Raw video data.

Return value

  • true: Needs to be written back to the SDK (default is to write back; must be written back when operating on AliRtcVideoSample.data).

  • false: Does not need to be written back to the SDK (used when directly operating on AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV).

onRemoteVideoSample

Callback for subscribed remote video data.

public boolean onRemoteVideoSample(String callId,AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);

This is the callback for getting subscribed remote video data. It is used to get the raw video frame data (such as YUV format) of a remote user. You can use this callback to implement custom processing logic (such as adding filters, watermarks, or transcoding) and decide whether to return the processed data to the SDK for subsequent rendering.

Parameters

Parameter

Type

Description

callId

String

User ID.

sourceType

AliRtcVideoSourceType

Video stream type.

videoSample

AliRtcVideoSample

Raw video data.

Return value

  • true: Needs to be written back to the SDK (default is to write back; must be written back when operating on AliRtcVideoSample.data).

  • false: Does not need to be written back to the SDK (used when directly operating on AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV).

onGetVideoFormatPreference

Video data output format.

public AliRtcVideoFormat onGetVideoFormatPreference();

Return value

The desired video output format.

onGetObservedFramePosition

Video data output content.

public int onGetObservedFramePosition();

This is the callback for getting the video data output content or type. You can use this callback to get the processing stage of the SDK's output video frame (such as after collection, before encoding, or after pulling).

Return value

The desired video output content. The type is an enumeration value of AliRtcVideoObserPosition, representing collected data, pulled data, or pre-encoding data.

onPublishLiveStreamStateChanged

Callback for bypass stream publishing state changes.

public void onPublishLiveStreamStateChanged(String streamUrl, AliRtcLiveTranscodingState state, AliEngineLiveTranscodingErrorCode errorCode);

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

state

AliRtcLiveTranscodingState

Bypass live streaming status.

errorCode

AliEngineLiveTranscodingErrorCode

Error code.

onPublishTaskStateChanged

Callback for bypass task state changes.

public void onPublishTaskStateChanged(String streamUrl, AliRtcTrascodingPublishTaskStatus state);

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

state

AliRtcTrascodingPublishTaskStatus

Bypass live stream publishing task status.

onNetworkQualityChanged

Callback for network quality changes.

public void onNetworkQualityChanged(String uid, AliRtcNetworkQuality upQuality, AliRtcNetworkQuality downQuality);

Parameters

Parameter

Type

Description

uid

String

User ID. When empty, it indicates the local user's uplink and downlink network status.

upQuality

AliRtcNetworkQuality

Uplink network status.

downQuality

AliRtcNetworkQuality

Downlink network status.

onNetworkQualityProbeTest

Callback for a network quality probe. This callback is provided about 3 seconds after the probe starts.

public void onNetworkQualityProbeTest(AliRtcNetworkQuality quality){}

Parameters

Parameter

Type

Description

quality

AliRtcNetworkQuality

Network quality.

onNetworkQualityProbeTestResult

Callback for the result of a network quality probe. This callback is provided about 30 seconds after the probe starts.

public void onNetworkQualityProbeTestResult(int code, AliRtcEngine.AlirtcNetworkQualityProbeResult result){}

Parameters

Parameter

Type

Description

code

int

Return value. 0 indicates the probe was successful. -1 indicates the probe failed and the connection was lost due to poor network conditions.

result

AlirtcNetworkQualityProbeResult

Network quality.

onSnapshotComplete

Callback interface for snapshot results.

public void onSnapshotComplete(String userId, AliRtcVideoTrack trackType, Bitmap bitmap, boolean success)

This interface notifies you of the snapshot result and details.

Parameters

Parameter

Type

Description

userId

String

User ID. If userId is null or "", it means a snapshot of the local user.

trackType

AliRtcVideoTrack

Snapshot video stream type.

bitmap

Bitmap

Snapshot data.

success

boolean

Whether the snapshot was successful.

onScreenSharePublishStateChanged

Callback for screen sharing publishing state changes.

public void onScreenSharePublishStateChanged(AliRtcEngine.AliRtcPublishState oldState , AliRtcEngine.AliRtcPublishState newState, int elapseSinceLastState, String channel)

This callback is a notification for screen sharing publishing state changes. It is triggered when the screen sharing publishing state changes.

Parameters

Parameter

Type

Description

oldState

AliRtcEngine.AliRtcPublishState

The old state before the publishing state change.

newState

AliRtcEngine.AliRtcPublishState

The new state after the publishing state change.

elapseSinceLastState

int

Time interval since the last state change (in milliseconds).

channel

String

The name of the current channel.

onScreenShareSubscribeStateChanged

Callback for screen sharing stream subscription state changes.

public void onScreenShareSubscribeStateChanged(String uid,
                                                    AliRtcEngine.AliRtcSubscribeState oldState,
                                                    AliRtcEngine.AliRtcSubscribeState newState,
                                                    int elapseSinceLastState, String channel);

This callback is a notification for screen sharing stream subscription state changes. It is triggered when the subscription status of the current user 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

Current subscription status.

elapseSinceLastState

int

Time interval since the last state change (in milliseconds).

channel

String

Current channel.

onOccurError

Error notification.

public void onOccurError(int error, String message);

This is the global error notification callback for the ARTC SDK. It notifies the application layer when a serious error occurs within the SDK's internal engine. You can use this callback to get the error code and error message for exception handling, logging, or user prompts.

Parameters

Parameter

Type

Description

error

int

Error type. See the error code list.

message

String

Error message.

OnLocalAudioStateChanged

Callback for local audio device status.

public void OnLocalAudioStateChanged(int state);

This callback is triggered when the status of the local audio collection device changes. For example, when you call startAudioCapture to start audio collection or call stopAudioCapture to stop it.

Parameters

Parameter

Type

Description

state

int

  • 0: Not created.

  • 1: Collecting.

  • 2: Closing collection.

  • 3: Collection closed.

setParameter

Sets custom parameters.

public abstract int setParameter(String param);

Parameters

Parameter

Type

Description

param

String

Custom parameters.

getParameter

Gets custom parameters.

public abstract String getParameter(String param);

Parameters

Parameter

Type

Description

param

String

Custom parameters.

registerAudioVolumeObserver

Registers a volume data output object.

public abstract void registerAudioVolumeObserver(AliRtcAudioVolumeObserver observer);

This interface registers an object that is used to export volume data. To unregister, call unRegisterAudioVolumeObserver.

When to call

  • When you need 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 method to register the object that receives the relevant data.

  • If you call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ae07dc986abf3" id="29e92857a5iv8">startAudioCaptureTest</a> to test your audio device before you join a meeting, 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

AliRtcAudioVolumeObserver

Volume data receiving object.

unRegisterAudioVolumeObserver

Unregisters a volume data output object.

public abstract void unRegisterAudioVolumeObserver();

This method corresponds to registerAudioVolumeObserver and is used to unregister the output object for audio volume data.

When to call

If you have registered an object to receive audio data by calling registerAudioVolumeObserver, call this method to unregister the object.

enableAudioFrameObserver

Sets audio callback parameters.

public abstract int  enableAudioFrameObserver(boolean enable, AliRtcAudioSource audioSource, AliRtcAudioFrameObserverConfig config);

This method enables or disables the audio data callback for a specified type, allowing you to get various raw and encoded audio data. It is disabled by default. To enable it, call this method.

Note

When you call this API to enable the audio data callback for the corresponding AliRtcAudioSource, you need to use the registerAudioFrameObserver method to pass an object to receive the audio data.

When to call

You can call this method to enable it when you need to get audio data.

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to allow audio data callbacks.

audioSource

AliRtcAudioSource

Callback data source type, including after collection (0), after 3A (1), publishing (2), playback (3), after publishing and playback mixing (4), and pulled audio data (5).

Note
  • Ingested audio data and mixed audio data from ingest and playback only support read-only (ReadOnly) mode.

  • Stream pulling audio data does not support modifying audio parameters such as sample rate and number of channels.

config

AliRtcAudioFrameObserverConfig

Audio callback parameter settings, including sample rate, number of channels, and callback read/write mode (read-only, write-only, read-write). If the parameter is null, the default is (48000, 1, ReadOnly).

Return value

  • 0: The method call succeeded.

  • <0: The method call failed.

registerAudioFrameObserver

Registers an audio data callback.

public abstract void registerAudioFrameObserver(AliRtcAudioFrameObserver observer);

This method registers the receiving object for audio callback data.

When to call

When you need the SDK to trigger the onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, or onRemoteUserAudioFrame callbacks to obtain various types of audio data, you need to call this method to provide an audio data receiving object. To unregister, call this method again and pass null.

Limits

You need to call enableAudioFrameObserver to enable the callback for the specific AliRtcAudioSource. Otherwise, the passed observer cannot obtain data.

Parameters

Parameter

Type

Description

observer

AliRtcAudioFrameObserver

Audio data callback receiving object instance. When null is passed, it means unregistering.

registerVideoSampleObserver

Registers a video data output object.

public abstract void registerVideoSampleObserver(AliVideoObserver observer);

Use this API to register the output object for video data. To cancel the registration, call the unRegisterVideoSampleObserver API.

When to call

To get raw audio data (such as YUV or RGBA format), you can call this method to register a video data observer to get video data at various stages. AliRtcVideoObserver is the video data observer class.

Related callbacks

After you successfully register a video data output observer, the SDK triggers the callbacks you implemented in the AliRtcVideoObserver interface when it captures each video frame. Implement the corresponding callbacks based on your business needs:

Parameters

Parameter

Type

Description

observer

AliRtcVideoObserver

Video data output object.

Return value

The output data is returned through the AliVideoObserver callback.

unRegisterVideoSampleObserver

Unregisters a video data output object.

public abstract void unRegisterVideoSampleObserver();

This API 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> API and unregisters the video data output object.

registerLocalVideoTextureObserver

Registers an OpenGL texture data observer for the local camera stream video.

public abstract void registerLocalVideoTextureObserver(AliTextureObserver observer);

If you want to obtain raw video data, call the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="4f1f5a423ch4j">registerVideoSampleObserver</a> interface to register the corresponding callback. If you want to obtain internal texture data, call this interface. To unregister, call the unRegisterLocalVideoTextureObserver interface.

Note

This method is only valid for local camera stream video.

Related callbacks

After you successfully register an OpenGL texture data observer for the local camera stream video, the SDK triggers the callbacks you implemented in the AliRtcTextureObserver interface when it captures each video frame. Implement the corresponding callbacks based on your business needs:

  • onTextureCreate: This callback is triggered when the internal OpenGL context of the SDK is created.

  • onTextureUpdate: This callback is triggered after each video frame is uploaded to the OpenGL texture. When an external OpenGL texture data observer is registered, you can process the texture in this callback and return the processed texture ID. Note that the return value of this callback must be a valid texture ID. If you do not perform any processing, you must return the textureId parameter.

  • onTextureDestroy: This callback is triggered when the internal OpenGL context of the SDK is destroyed.

Parameters

Parameter

Type

Description

observer

AliRtcTextureObserver

OpenGL texture data observer.

Return value

The output data is returned through the AliVideoObserver callback.

unRegisterLocalVideoTextureObserver

Unregisters the OpenGL texture data observer for the local camera stream video.

public abstract void unRegisterLocalVideoTextureObserver();

This method corresponds to registerLocalVideoTextureObserver and unregisters the observer.

snapshotVideo

Video snapshot feature.

public abstract int snapshotVideo(String userId, AliRtcVideoTrack trackType);

Call this method to take a snapshot of a specified user's specified video stream.

Limits

This is an asynchronous operation. When the call returns 0, it means the method call was successful, but the SDK has not actually taken the snapshot yet.

Related callbacks

After you successfully call this method, you can listen to the onSnapshotComplete callback to obtain the result and details of the screenshot.

Parameters

Parameter

Type

Description

userId

String

User ID. If userId is null or "", it means a snapshot of the local user.

trackType

AliRtcVideoTrack

Video stream type. It indicates which stream to take a snapshot of. Only the following are supported:

  • AliRtcVideoTrackCamera: Camera stream.

  • AliRtcVideoTrackScreen: Screen sharing stream.

Return value

  • 0: The method call was successful. Whether the snapshot was successful is given by the onSnapshotComplete callback.

  • Non-zero: The call failed. An error code is returned.

setLogDirPath

Sets the save path for SDK log files.

public static int setLogDirPath(String logDirPath);

Parameters

Parameter

Type

Description

logDirPath

String

The absolute path to save the log files. Default path: under the app directory.

Return value

0 indicates the method call was successful. A non-zero value indicates a failure. Note: To call this method, set it before calling any other SDK methods to avoid log loss. The application 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

AliRtcLogLevel

Log level.

setDeviceOrientationMode

Sets the device orientation.

public abstract void setDeviceOrientationMode(AliRtcOrientationMode mode);

This method sets the orientation mode of the device, which affects the display of the video.

Limits

Only Android and iOS have this interface.

Parameters

Parameter

Type

Description

mode

AliRtcOrientationMode

Device orientation.

Return value

None.

requestAudioFocus

Requests audio focus.

public abstract int requestAudioFocus();

When to call

When the SDK starts, it requests audio focus internally. Generally, you do not need to actively request audio focus. If you have actively called abandonAudioFocus, you can call this method to restore audio focus.

Limits

For Android only.

Parameters

None.

Return value

  • 0: Failure.

  • 1: Success.

abandonAudioFocus

Abandons audio focus.

public abstract int abandonAudioFocus();

When to call

During the SDK destruction process, this method is called internally to release the audio focus. In some scenarios, you may need to actively release the audio focus. You can call this method to do so. After releasing the audio focus, some devices may have no sound or low volume during playback. To restore the audio, you can call requestAudioFocus.

Limits

For Android only.

Return value

  • 0: Failure.

  • 1: Success.

getNetworkTime

Gets the current network time.

public abstract long getNetworkTime();

This method gets the current network time (the current timestamp after NTP calibration and considering the time offset), in ms.

When to call

When performing multi-end behavior synchronization, you need to get the synchronized network time as a baseline to calibrate the current time.

Return value

The current Network Time Protocol (NTP) time (in milliseconds).

sendDataChannelMsg

Sends a custom data channel message.

public abstract int sendDataChannelMsg(AliRtcDataChannelMsg Msg);

The ARTC SDK provides the ability to send and receive custom messages, allowing you to send custom real-time message data while transmitting audio and video data. You can call this method to transmit real-time control instructions, state synchronization data, or other business messages along with the audio and video. For more information, see Send and receive custom messages.

Note
  • The custom message channel is disabled by default. To enable this feature, call the setParameter interface and set the parameter to "{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}". You can do this either before or after joining a channel.

  • The message can be any data (such as text).

Related callbacks

  • After the sender successfully enables a custom message channel, they can call this method to send a custom message. The receiver receives the custom message by listening for the onDataChannelMessage callback.

Limits

  • Streamers can send and receive messages. Viewers can only receive messages.

  • You need to call setParameter to enable the custom message channel.

  • The data sending is limited to:

    • A maximum bitrate of 30 KB/s.

    • The data channel can send a maximum of 60 data packets per second, with each packet up to 1 KB.

Parameters

Parameter

Type

Description

Msg

AliRtcDataChannelMsg

Message content.

Return value

  • 0: Success.

  • Non-zero: Failure. An error code is returned.

startScreenShare

Important

This interface will be deprecated. We recommend that you use the new interface startScreenShare.

Starts sharing the screen and audio stream.

public abstract int startScreenShare(Intent intent);

Parameters

Name

Description

intent

An externally created Activity to start screen sharing. If not created externally, pass null. We recommend passing null.

Return value

  • 0: Success.

  • Other: Failure.

startScreenShare

Important

This interface will be deprecated. We recommend using the new interface startScreenShare.

Starts screen sharing.

public abstract int startScreenShare();

Return value

  • 0: Success.

  • Other: Failure.

startScreenShare

Starts sharing the screen video stream.

public abstract int startScreenShare(Intent intent, AliRtcScreenShareMode screenShareMode);

Parameters

Name

Description

intent

An externally created Activity to start screen sharing. If not created externally, pass null. We recommend passing null.

screenShareMode

Screen sharing type. For more information, see AliRtcScreenShareMode.

Return value

  • 0: Success.

  • Other: Failure.

stopScreenShare

Stops the screen sharing stream, including the shared audio stream.

public abstract int stopScreenShare();

Return value

  • 0: Success.

  • Other: Failure.

setAudioShareVolume

Sets the shared audio stream volume.

public abstract int setAudioShareVolume(int volume);

Parameters

Name

Description

volume

Volume level.

The range is [0, 100]. The default value is 50.

Return value

  • 0: Success.

  • Other: Failure.

isScreenSharePublished

Queries whether the screen sharing stream is being published.

public abstract boolean isScreenSharePublished();

Return value

  • true: Screen sharing is being published.

  • false: Screen sharing is not being published.

setScreenShareEncoderConfiguration

Sets the video encoding properties for the screen stream.

public abstract void setScreenShareEncoderConfiguration(AliRtcScreenShareEncoderConfiguration config);

This method sets the video parameters for the screen stream video encoding properties, such as resolution, frame rate, bitrate, and video orientation.

Note

All set parameters have corresponding range limits. If a set parameter is outside the valid range, the SDK automatically adjusts it. Therefore, the actual configuration may differ from your configuration.

When to call

You can call this method before or after joining a channel. If you only need to set the screen stream video encoding properties once per session, we recommend calling it before joining the channel.

Parameters

Parameter

Type

Description

config

AliRtcScreenShareEncoderConfiguration

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 global operating environment for the SDK. It mainly affects the destination for log reporting and instrumentation data transmission:

  • When set to the domestic environment, logs and instrumentation data are reported to data centers in the Chinese mainland.

  • When set to the overseas environment, the data is routed to data centers outside China, such as in Singapore.

When to call

We recommend calling this method early in the application initialization, such as in the onCreate() method of the Application class.

Limits

  • This setting is global and only needs to be called once.

  • Multiple calls will overwrite the previous environment configuration but may affect established connections or session states. Do not switch dynamically during runtime.

Example

AlivcEnv.GlobalEnv env = ENV_DEFAULT; // For overseas environments, use ENV_SEA
AlivcBase.getEnvironmentManager().setGlobalEnvironment(env);

Parameters

Parameter

Type

Description

env

GlobalEnv

Specifies the global environment. Supported enumeration values:
• ENV_DEFAULT: Domestic environment.
• ENV_SEA: Overseas environment (such as Singapore).

Return value
Returns an int type result code:

  • 0: Indicates success.

  • A non-0 value indicates failure.