All Products
Search
Document Center

Intelligent Media Services:AliRtcEngine API reference

Last Updated:Dec 28, 2025

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

Contents

Basic APIs

API

Description

getInstance[1/2]

Creates an AliRtcEngine instance in singleton mode.

getInstance[2/2]

Creates an AliRtcEngine instance in singleton mode.

destroy[1/2]

Destroys the AliRtcEngine object.

destroy[2/2]

Destroys the AliRtcEngine object.

setH5CompatibleMode

Sets the H5 compatibility mode.

getH5CompatibleMode

Checks whether H5 compatibility is enabled.

setRtcEngineEventListener

Sets a listener for callback events related to the local user's behavior.

setRtcEngineNotify

Sets a listener for notification events related to remote users' behavior.

getSdkVersion

Gets the current SDK version.

Channel-related APIs

API

Description

setChannelProfile

Sets the channel mode.

setAudioProfile

Sets the audio encoding mode and scenario.

isAudioOnly

Checks 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 subscribing APIs

API

Description

publishLocalAudioStream

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

isLocalAudioStreamPublished

Checks whether the audio stream is being published.

setDefaultSubscribeAllRemoteAudioStreams

Sets whether to automatically subscribe to audio streams. By default, all remote audio streams are subscribed. Call this API before you join a channel.

subscribeRemoteAudioStream

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

subscribeAllRemoteAudioStreams

Stops or resumes subscribing to all remote audio streams.

publishLocalVideoStream

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

isLocalVideoStreamPublished

Checks whether the video stream is currently being published.

setDefaultSubscribeAllRemoteVideoStreams

Sets whether to automatically subscribe to video streams. By default, all remote video streams are subscribed. Call this API before you join 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 subscribing to the media stream of a specific remote user. Use this API when both audio and video streams exist and need to be controlled.

subscribeRemoteMediaStream[2/2]

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

subscribeRemoteDestChannelStream

Stops or resumes subscribing to the media stream of a specific remote user in another channel.

subscribeRemoteDestChannelAllStream

Stops or resumes subscribing to the streams of all users in another channel.

setRemoteAudioVolume

Adjusts the playback volume of a subscribed stream.

Audio device management APIs

API

Description

muteLocalMic

Sets whether to stop publishing the local audio.

muteRemoteAudioPlaying

Sets whether to stop playing the remote audio stream.

muteAllRemoteAudioPlaying

Stops or resumes playback of all remote audio.

startAudioCapture[1/2]

Enables audio capture.

startAudioCapture[2/2]

Enables audio capture.

stopAudioCapture

Disables audio capture.

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 device detection before a call.

stopAudioCaptureTest

Disables audio device detection.

Audio voice changing and reverb

API

Description

setAudioEffectVoiceChangerMode

Sets the voice changing effect mode.

setAudioEffectPitchValue

Sets the pitch shifting parameter.

setAudioEffectReverbMode

Sets the reverb effect mode.

setAudioEffectReverbParamType

Sets the reverb effect type and specific parameters.

Custom audio input

API

Description

addExternalAudioStream

Adds an external audio stream.

pushExternalAudioStreamRawData

Inputs external audio stream data.

setExternalAudioStreamPublishVolume

Sets the publishing volume.

getExternalAudioStreamPublishVolume

Gets the publishing volume.

setExternalAudioStreamPlayoutVolume

Sets the playback volume of the external audio stream.

getExternalAudioStreamPlayoutVolume

Gets the playback volume of the external audio stream.

removeExternalAudioStream

Removes 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 and publishing volumes.

setAudioAccompanyPublishVolume

Sets the accompaniment publishing volume.

getAudioAccompanyPublishVolume

Gets the accompaniment publishing 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 mixing volume for publishing a sound effect.

getAudioEffectPublishVolume

Gets the mixing volume for publishing a sound effect.

setAllAudioEffectsPublishVolume

Sets the mixing volume for publishing 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 APIs

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 camera capture preferences.

enableLocalVideo

Disables or re-enables local video capture.

muteLocalCamera

Sets whether to stop publishing the local video stream.

isCameraOn

Checks whether the camera is on.

setVideoEncoderConfiguration

Sets video encoding properties.

setVideoDecoderConfiguration

Sets 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 factor.

GetCameraMaxZoomFactor

Gets the maximum zoom factor supported by the camera.

GetCurrentZoom

Gets the current camera zoom factor 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

Turns 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 publishing.

setCapturePipelineScaleMode

Sets the timing for video capture scaling.

Configure video data callbacks

API

Description

registerVideoSampleObserver

Registers a video data output object.

unRegisterVideoSampleObserver

Unregisters a video data output object.

registerLocalVideoTextureObserver

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

unRegisterLocalVideoTextureObserver

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

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.

Screen sharing APIs

API

Description

startScreenShare

Starts publishing the screen sharing stream.

startScreenShare

Starts to share the screen and audio stream.

Note

This API is deprecated.

startScreenShare

Starts screen sharing.

Note

This API is deprecated.

stopScreenShare

Stops publishing the screen sharing stream.

setAudioShareVolume

Sets the volume of the shared audio stream.

isScreenSharePublished

Checks whether screen sharing is being published.

setScreenShareEncoderConfiguration

Sets video encoding properties for the screen stream.

Bypass live streaming APIs

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 probing APIs

API

Description

startNetworkQualityProbeTest

Starts network quality probing.

stopNetworkQualityProbeTest

Stops network quality probing.

SEI

API

Description

sendMediaExtensionMsg

Pushes an SEI stream.

sendMediaExtensionMsgEx

Pushes an SEI stream (extended).

Other APIs

API

Description

setParameter

Sets custom parameters.

getParameter

Gets custom parameters.

setLogDirPath

Sets the path to save 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.

Callback events

AliRtcEngineEventListener

API

Description

onConnectionStatusChange

Callback for network connection status. You must handle this callback.

OnLocalDeviceException

Callback for local device exceptions. You must 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 network quality probing. This callback is provided about 3 seconds after probing starts.

onNetworkQualityProbeTestResult

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

onSnapshotComplete

Callback 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 will expire 30 seconds after this notification is received. You must handle this callback.

onAuthInfoExpired

The server returns that the information has expired when the user calls an API 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 audio device interruption has started.

onUserAudioInterruptedEnded

Notification that 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 capture.

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 media extension information.

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 of the preview starts to display.

onFirstVideoFrameReceived

Callback for receiving the first video frame of 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 status.

onRemoteAudioAccompanyStarted

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

onRemoteAudioAccompanyFinished

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

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

Callback for voice activity detection, triggered when an active user is detected.

OnTestAudioVolume

Callback for volume information during pre-call testing.

AliRtcAudioFrameObserver

API

Description

onCapturedAudioFrame

Callback for raw audio capture data.

onProcessCapturedAudioFrame

Callback for audio data after 3A processing.

onPublishAudioFrame

Callback for published audio data.

onPlaybackAudioFrame

Callback for playback data.

onRemoteUserAudioFrame

Callback for remote subscribed stream data.

AliRtcDestroyCompletionObserver

API

Description

OnDestroyCompletion

Callback for engine destruction completion.

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 capture 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.

API details

getInstance[1/2]

Creates an AliRtcEngine instance in singleton mode.

public static AliRtcEngineImpl getInstance(Context context);
Note
  • Both this method and getInstance[2/2] create an AliRtcEngine instance. The getInstance[2/2] method lets you specify more configurations during creation.

When to call

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

Limits

The SDK supports only one AliRtcEngine instance per application.

Parameters

Parameter

Type

Description

context

Context

The context of the Android Activity.

Return value

Returns an AliRtcEngine instance. The SDK supports only one AliRtcEngine instance per application.

getInstance[2/2]

Creates an AliRtcEngine instance in singleton mode.

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 create an AliRtcEngine instance, but this method lets you specify more configurations during creation.

When to call

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

Limits

The SDK supports only one AliRtcEngine instance per 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

A singleton instance of the AliRtcEngineImpl class. AliRtcEngineImpl is a child class of the AliRtcEngine class.

destroy[1/2]

Destroys the AliRtcEngine object.

public abstract void destroy();

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

Note
  • Both this method and destroy[2/2] destroy the engine instance. The destroy[2/2] method lets you pass a listener object to monitor the completion of the destruction.

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

When to call

After your real-time communication session ends, call this method to release the instance. This reduces unnecessary resource usage.

Limits

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

  • After calling 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. After this method is called, all internal resources are released. Other methods and callbacks of AliRtcEngine become unavailable. To use the SDK again, call getInstance to create a new instance.

Note

This is an asynchronous method. It provides an observer that lets you monitor when the destruction is complete. You can create a new instance only after the OnDestroyCompletion callback is returned. The destruction is not complete until the observer callback is triggered.

When to call

Call this method to release the instance after the real-time communication is complete.

Limits

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

Related callbacks

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

Parameters

Parameter

Type

Description

observer

AliRtcDestroyCompletionObserver

A notification callback for engine destruction completion. You can listen to this callback to ensure resources are fully released.

setH5CompatibleMode

Sets whether H5 compatibility is enabled.

public static int setH5CompatibleMode(int enable);

Parameters

Parameter

Type

Description

enable

int

Sets whether to enable H5 compatibility. Valid values:

  • 0 (default): H5 compatibility is disabled.

  • 1: H5 compatibility is enabled.

Important

The current version does not support changing the H5 compatibility mode after an AliRtcEngine instance is created. You must call this API before you create the instance.

getH5CompatibleMode

Checks whether H5 compatibility is enabled.

public static int getH5CompatibleMode();

Return value

  • 1: H5 compatibility is enabled.

  • 0: H5 compatibility is disabled.

setRtcEngineEventListener

Sets a listener for notification events related to the local user's behavior.

public abstract void setRtcEngineEventListener(AliRtcEngineEventListener listener);

This API sets a listener to receive callbacks 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 status changes, audio and video subscription status changes, network quality changes and probing results, snapshot results, device status and exception notifications, and SDK error notifications. Implement the callback methods of this class to handle the lifecycle and status changes of the local user's RTC session.

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

  • To implement callbacks related to remote users, first frame or packet events, sound effect and accompaniment playback status, and authentication information, implement the relevant callbacks of the AliRtcEngineNotify class and call the setRtcEngineNotify API.

  • 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 you join a channel.

Related callbacks

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

Cause of exception

Callback and parameters

Solution

Description

Authentication failed

The result parameter in the onJoinChannelResult callback returns AliRtcErrJoinBadToken.

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

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

Network connection exception

The onConnectionStatusChange callback returns AliRtcConnectionStatusFailed.

If this exception occurs, rejoin the channel.

The SDK can automatically recover from network disconnections for a certain period. However, if the disconnection time exceeds a preset threshold, it will time out and disconnect. At this point, the app should check the network status and guide the user to rejoin the channel.

Local device exception

onLocalDeviceException

If this exception occurs, 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 app needs to intervene to check if the device is normal.

Parameters

Parameter

Type

Description

listener

AliRtcEngineEventListener

Sets a listener for notification events related to the local user's behavior.

setRtcEngineNotify

Sets a listener for notification events related to remote users' behavior.

public abstract void setRtcEngineNotify(AliRtcEngineNotify listener);

This API sets a listener to receive callbacks for events related to remote users. These events include notifications of remote users coming online or going offline, remote user audio and video publishing status, remote user resolution changes, the sending and receiving status of the first frame or packet for local and remote audio and video, the playback status of local and remote sound effects and accompaniment, mute status, local and remote audio and 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 interactions with remote users.

Note
  • By default, all methods have empty implementations. You do not need to implement all methods. 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 you join a channel.

Related callbacks

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

Cause of 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 service and needs to rejoin the channel.

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

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

Authentication is about to expire

onWillAuthInfoExpire

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

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

Authentication has expired

onAuthInfoExpired

If this exception occurs, rejoin the channel.

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

Parameters

Parameter

Type

Description

listener

AliRtcEngineNotify

Sets a listener for notification events related to remote users' behavior to receive messages from the engine.

getSdkVersion

Gets the current SDK version.

public static String getSdkVersion();

Return value

The current SDK version number as a string, for example, "2.5.0.x".

setChannelProfile

Sets the channel mode.

public abstract int setChannelProfile(AliRTCSdkChannelProfile channelProfile);

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

  • Video call mode: All users are in the streamer role and can publish and subscribe to streams.

  • Interactive stream mode: In this 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 user roles. Users who ingest streams in the channel are set to the streamer role (AliRTCSdkInteractive). If a user only needs to pull streams and does not ingest streams, they are set to the viewer role (AliRTCSdkLive). This mode is recommended for RTC scenarios.

Note
  • The interactive stream mode is recommended for all RTC scenarios. To use this mode, call this API and set the mode to AliRTCSdkInteractiveLive.

  • Users in the same channel must use the same channel mode.

When to call

This API can only be called before you join a channel. It cannot be reset during a session. It can be reset after you leave the channel.

Parameters

Parameter

Type

Description

channelProfile

AliRTCSdkChannelProfile

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

Return value

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

setAudioProfile

Sets the audio encoding mode and scenario.

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

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

When to call

This API can only be called before you join a channel. It cannot be reset after you join a channel. It can be reset after you leave the channel.

Parameters

Parameter

Type

Description

profile

AliRtcAudioProfile

Audio capture or encoding mode parameter. High-quality mode (AliRtcEngineHighQualityMode) is recommended.

Note

To interoperate with web clients, set the sample rate to 48 kHz.

  • AliRtcEngineLowQualityMode: Low-quality audio mode. Default sample rate is 8000 Hz, mono, with a maximum encoding bitrate of 12 kbps.

  • AliRtcEngineBasicQualityMode: Standard-quality audio mode. Default sample rate is 16000 Hz, mono, with a maximum encoding bitrate of 24 kbps.

  • AliRtcEngineHighQualityMode: Default sample rate is 48000 Hz, mono, with a maximum encoding bitrate of 64 kbps.

  • AliRtcEngineStereoHighQualityMode: Stereo high-quality audio mode. Default sample rate is 48000 Hz, stereo, with a maximum encoding bitrate of 80 kbps.

  • AliRtcEngineSuperHighQualityMode: Super high-quality audio mode. Default sample rate is 48000 Hz, mono, with a maximum encoding bitrate of 96 kbps.

  • AliRtcEngineStereoSuperHighQualityMode: Stereo super high-quality audio mode. Default sample rate is 48000 Hz, stereo, with a maximum encoding bitrate of 128 kbps.

scenario

AliRtcAudioScenario

Audio scenario parameter. It mainly includes:

  • AliRtcSceneMusicMode (recommended): Music scenario. Uses software 3A and captures from the phone for higher audio quality.

  • AliRtcSceneDefaultMode: Uses hardware 3A. Can capture from Bluetooth devices.

Return value

0 indicates a successful call. A value less than 0 indicates a failed call.

isAudioOnly

Checks if 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 subscribed.

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

Return value

0 indicates that the method call is successful. A non-zero value indicates that the method call failed.

joinChannel[1/3]

Joins a channel using single-parameter authentication.

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

This method joins a channel. Alibaba Real-Time Communication (ARTC) organizes users into channels. A user must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[2/3], and joinChannel[3/3] all let you join a channel. They differ in their authentication methods and the user information they pass:

  • This is a single-parameter channel joining method. To join a channel, pass the token generated with Token authentication. Use this method for real-time communication (RTC) scenarios.

  • joinChannel[2/3] is a multi-parameter interface for joining a channel. You must pass the multi-parameter channel joining token generated by Token authentication and the user information that was used to generate the token.

  • joinChannel[3/3] 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 publish your own audio and video streams to remote users. If you want to cancel this default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="33438e1082mi8">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="243e9483a0suk">setDefaultSubscribeAllRemoteVideoStreams</a> before you call this method to disable the automatic subscription to audio or video streams.

When to call

Call this method after creating the engine.

Call limits

  • After you successfully join a channel, 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 <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="70c68b0236xdt">onLeaveChannelResult</a> callback from AliRtcEngineEventListener before you can join another channel.

  • A user can be in only one channel at a time.

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

  • The SDK automatically retries joining a channel if the initial attempt fails. Do not call this method again to retry.

Related callbacks

A successful call to this method triggers the following callbacks:

  • The result of the local user joining a channel is returned in 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 the channel, remote clients trigger the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7298cad465wnd" id="40a9273affui1">onRemoteUserOnLineNotify</a> callback.

Parameters

Parameter

Type

Description

token

String

The authentication information for single-parameter authentication.

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. This is not the user ID.

Return value

0 indicates that the method call was successful. A non-zero value indicates that the method call failed.

joinChannel[2/3]

Joins a channel using multiple parameters.

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

Use this method to join a channel. Alibaba Real-Time Communication (ARTC) uses channels to organize users. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[3/3] all let you join a channel. They differ in their authentication methods and the user information they pass. The differences are as follows:

  • joinChannel[1/3] is a single-parameter method. To join a channel, pass a token generated for single-parameter authentication. For more information, see Token-based authentication. This method is recommended for RTC scenarios.

  • This multi-parameter interface for joining a channel requires you to pass a multi-parameter 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. Pass a single-parameter joining 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 publish your own audio and video streams to remote users. To disable this default subscription, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="474adcf738uxu">setDefaultSubscribeAllRemoteAudioStreams</a> and setDefaultSubscribeAllRemoteVideoStreams before you call this API to disable the subscription to audio or video streams.

  • This API requires multiple parameters to join a channel. Before you call this API, refer to Token Authentication to generate the required token.

Call limits

  • After you successfully join a channel, 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="e2525ba6a0k3s">leaveChannel</a> to leave the current channel, and ensure that you receive, from AliRtcEngineEventListener, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="6aefdfedb0op3">onLeaveChannelResult</a> callback before you can join another channel.

  • A user can join only one channel at a time.

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

Related callbacks

A successful call to this method triggers the following callbacks:

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

  • After you successfully join a channel, remote clients trigger 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

The authentication information. The token must be a multi-parameter token. Other parameters must match those used to generate the token and cannot be empty.

userName

String

The display name of the user, not the user ID. This parameter can be empty.

Return value

Returns 0 if the method call is successful. Returns a non-zero value if the call fails.

joinChannel[3/3]

Joins a channel (single-parameter join).

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

This method joins a channel. Alibaba Real-Time Communication (ARTC) organizes users into channels. Users must join a channel to publish or subscribe to audio and video streams. This method, joinChannel[1/3], and joinChannel[2/3] all let you join a channel. They differ in their authentication methods and the user information they pass, as follows:

  • joinChannel[1/3] is a single-parameter method for joining a channel in RTC scenarios. Pass a token generated for a single-parameter join using Token authentication. This method is recommended for joining channels in RTC scenarios.

  • joinChannel[2/3] is a multi-parameter method. Pass a token generated for a multi-parameter join using Token authentication and the user information used to generate the token.

  • This method is for Real-time Conversational AI scenarios. Pass a single-parameter token to join a session. Set the user property capabilityProfile based on the scenario. For calls 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 publish 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="5423d42229iih">setDefaultSubscribeAllRemoteAudioStreams</a> and <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#c90127d90d22o" id="0112175788ybe">setDefaultSubscribeAllRemoteVideoStreams</a> before calling this API to disable the automatic subscription to audio or video streams.

Calling restrictions

  • After you successfully join a channel, 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="719d580348a95">leaveChannel</a> to leave the current channel and ensure that AliRtcEngineEventListener receives the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="d128acfee2fpd">onLeaveChannelResult</a> callback before you can join a new channel.

  • A user can join only one channel at a time with this method.

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

  • Do not call this method to retry joining a channel if the initial attempt fails.

Related callbacks

A successful call to this method triggers the following callbacks:

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

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

Parameters

Parameter

Type

Description

token

String

The token for a single-parameter join.

channelParam

AliRTCSdkChannelParam

Parameters for joining a channel. These are mainly for AI real-time interaction scenarios and include the following:

  • channelId: The channel ID. It must match the ID used to generate the token. This parameter is optional.

  • userId: The user ID for joining the channel. It must match the ID used to generate the token. This parameter is optional.

  • userName: The display name for the user. This is not the user ID. This parameter is optional.

  • capabilityProfile: The user property. Configure this for AI agent communication scenarios. For other scenarios, use the default value.

Return value

0 indicates that the method was called successfully. A non-zero value indicates that the call failed.

leaveChannel

Leaves the channel. After you call this method, the SDK stops audio and video interaction and leaves the current channel.

public abstract int leaveChannel();
Note
  • This method is an asynchronous operation. A successful call to this method 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 to leave a channel after you have joined it.

  • If you are in a channel and want to join another one, call this method first to leave the current channel.

Related callbacks

  • Local user: Calling this method triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8c189be470bsp" id="80f5e30245vfn">onLeaveChannelResult</a> callback to provide the result of leaving the channel.

  • Remote users: After this API is called successfully, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#75c700a2376c1" id="69bf5ff199oda">onRemoteUserOffLineNotify</a> callback is triggered for remote users.

Return value

A return value of 0 indicates that the method was called successfully. A non-zero value indicates that the call failed.

isInCall

Checks if you are in a channel.

public abstract boolean isInCall();

Return value

Returns true if you are in a channel, and false otherwise.

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 you join a channel:

  • Set the user role to streamer: The SDK automatically publishes local audio and video streams and receives streams from other streamers.

  • Set the user role to viewer: The SDK does not publish local audio and video streams, but receives streams from other streamers.

When to call

Call this method either before or after you join a channel. Set the user role before you join, or switch the role after you join.

Limitations

This method works only in interactive mode. To use this method, you must call the setChannelProfile method to set the channel profile to AliRTCSdkInteractiveLive.

In interactive mode, explicitly set the user role before you join the channel.

Parameters

Parameter

Type

Description

clientRole

AliRTCSdkClientRole

The user role. This parameter is effective only in interactive mode.

getCurrentClientRole

Gets the user role.

public abstract AliRTCSdkClientRole getCurrentClientRole();

Return value

The current user role.

refreshAuthInfo[1/2]

Refreshes the authentication information.

public abstract int refreshAuthInfo(AliRtcAuthInfo authInfo);

This method updates the authentication information. A token expires after a certain period. When the token expires, the software development kit (SDK) cannot connect to the server.

Note

Both this method and refreshAuthInfo[2/2] update authentication information. Use this method to update the token for joining a channel with multiple parameters. Use refreshAuthInfo[2/2] to update the token for joining a channel with a single parameter. For more information about how to generate a token, see Token-based authentication.

When to call

In the following scenarios:

  • When you receive the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e9acb46a25uym" id="7e1510bec7s3s">onAuthInfoWillExpire</a> callback reporting that the authentication information is about to expire, 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 to indicate that the authentication has expired. You must then regenerate a Token and call joinChannel to rejoin the channel.

Parameters

Parameter

Type

Description

authInfo

AliRtcAuthInfo

The authentication information.

Return value

A return value of 0 indicates that the method call succeeded. Other values indicate that the method call failed.

refreshAuthInfo[2/2]

Refreshes the authentication information.

public abstract int refreshAuthInfo(String token);

This method updates the token. Tokens expire after a certain period. After a token expires, the SDK can no longer connect to the server.

Note

Both this method and refreshAuthInfo[1/2] update authentication information. This method updates the token used to join a channel with a single parameter. The refreshAuthInfo[1/2] method updates the token used to join a channel with multiple parameters. For more information about token generation, see Token-based authentication.

When to call

Regenerate a token on your server and then call this method to pass in the new token under the following circumstances:

  • When you receive the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e9acb46a25uym" id="d708af68eevs9">onAuthInfoWillExpire</a> callback reporting that the authentication information is about to expire.

  • If the token is not updated in time, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#8fa7e60f9f5qq" id="3fd674e985gl8">onAuthInfoExpired</a> callback is triggered, indicating that the authentication has expired. At this point, you must call joinChannel to rejoin the channel.

Parameters

Parameter

Type

Description

token

String

The authentication token for a single-parameter join.

Return value

A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

publishLocalAudioStream

Stops or resumes publishing the local video stream.

public abstract int publishLocalAudioStream(boolean enable);

This method controls whether to publish the local audio stream. By default, the SDK publishes the audio stream. To disable this default behavior, call publishLocalAudioStream(false) before joining a channel.

When to call

Call this method before or after joining a channel. If you call it before joining a channel, it modifies the default configuration. The new configuration takes effect when you join the channel.

Related callbacks

When the status of the local audio stream ingest changes, the local client triggers the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#b7e3bb51c2ga9" id="4ced92c3f5hmj">onAudioPublishStateChanged</a> callback to notify you of the new ingest status, while remote clients trigger <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="2b5460d448ga9">onRemoteTrackAvailableNotify</a> to notify you of the change in the remote user's stream availability.

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 that the method was called successfully. Other values indicate that the call failed.

isLocalAudioStreamPublished

Checks whether the local audio stream is published.

public abstract boolean isLocalAudioStreamPublished();

Return value

Returns true if the local audio stream is published, or false otherwise.

setDefaultSubscribeAllRemoteAudioStreams

Sets whether to subscribe to remote audio streams by default.

public abstract int setDefaultSubscribeAllRemoteAudioStreams(boolean sub);

This method configures the default subscription behavior for remote audio streams. This setting affects users who join the channel after this method is called. For most scenarios, set this to true.

When to call

Call this method before or after joining a channel.

  • Before joining a channel:

    • By default, the software development kit (SDK) subscribes to remote audio streams when joining a channel. To change this behavior, call this method before joining the channel.

  • After joining a channel:

    • To stop the default subscription, call setDefaultSubscribeAllRemoteAudioStreams(false). The SDK will not subscribe to the audio streams of users who join the channel afterward.

    • After stopping the default subscription, call the subscribeRemoteAudioStream method to resume subscribing to a specific user's audio stream. To resume subscribing to multiple users, call the method for each user.

    • After stopping the default subscription, calling setDefaultSubscribeAllRemoteAudioStreams(true) only resumes the audio streams from users who join the channel afterward. The SDK does not subscribe to the audio streams of remote users who joined while the default subscription was stopped.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to subscribe to remote audio streams by default. The valid values are:

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

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

Returns

0 indicates a successful call. A non-zero value indicates a failed call.

subscribeRemoteAudioStream

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

public abstract int subscribeRemoteAudioStream(String uid, boolean sub);

Call this method to stop or resume subscribing to the audio stream of a specific remote user. For most scenarios, set the sub parameter 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_1_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="d319c7806ej0h">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before joining the channel to cancel this default configuration.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

sub

boolean

Specifies whether to stop or resume subscribing to the audio stream of the remote user. Valid values:

  • true (default): Resumes subscribing.

  • false: Stops subscribing.

Return value

Returns 0 if the method is called successfully. Returns a value other than 0 if the call fails.

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. Set this parameter to true in most cases. If you set it to false, the following occurs:

  • The SDK stops subscribing to all remote audio streams in the current channel.

  • The SDK will not subscribe to new users who join the channel.

  • You cannot use <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#e09342eeb0z4k" id="a56b5f2a3f56k">subscribeRemoteAudioStream</a> to individually control the audio stream of a specific user.

To re-subscribe, call this API again and set it to true to resume the subscription.

Note

The SDK subscribes to the audio streams of all remote users by default when you join a session. To modify this behavior, you can call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0155f66448env" id="5a57cb846fzb2">setDefaultSubscribeAllRemoteAudioStreams</a>(false) before you join the session to cancel 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 any remote audio streams.

Return value

A value of 0 indicates that the method call succeeded. Any other value indicates that the call failed.

publishLocalVideoStream

Sets whether to publish the camera stream.

public abstract int publishLocalVideoStream(boolean enable);

This method controls whether to publish the video stream captured by the local camera.

Note

The software development kit (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.

Call this method to modify the default configurations before you join a channel. The changes take effect when you join the channel.

Related callbacks

When the local audio stream ingest status changes, the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#afe6d3c4b1rvg" id="8b70bc353aj68">onVideoPublishStateChanged</a> callback is triggered on the local client to report the latest status of the audio stream ingest. The <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#7078e15087a0z" id="176ee94b46lb7">onRemoteTrackAvailableNotify</a> callback is triggered on the remote client to indicate that the remote user's audio and video streams have changed.

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.

Returns

A value of 0 indicates a successful method call. A non-zero value indicates a failed call.

isLocalVideoStreamPublished

Checks if the camera stream is published.

public abstract boolean isLocalVideoStreamPublished();

Return value

true if the camera stream is published. false otherwise.

setDefaultSubscribeAllRemoteVideoStreams

Sets whether to subscribe to all remote video streams by default.

public abstract int setDefaultSubscribeAllRemoteVideoStreams(boolean sub);

Use this method to set the default video stream subscription behavior. By default, the SDK subscribes to video streams.

When to call

Call this method before or after you join a channel. If you call setDefaultSubscribeAllRemoteVideoStreams(false) after joining a channel, you will not receive video streams from users who subsequently join the channel.

To resume a video stream from a specific remote user, call subscribeRemoteVideoStream and specify the user's ID. To resume video streams from multiple users, call subscribeRemoteVideoStream multiple times. Calling setDefaultSubscribeAllRemoteVideoStreams(true) only resumes video streams from users who join the channel after the method is called.

This method sets the default subscription for remote video streams.

Note

By default, the SDK subscribes to remote audio and video streams when a user joins a channel. To change this behavior, call this method before joining the channel.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to subscribe to video streams by default.

  • true (default): Subscribe to video streams by default.

  • false: Do not subscribe to video streams by default.

Return value

A value of 0 indicates the method call succeeded. Any other value indicates it failed.

subscribeRemoteVideoStream

Stops or resumes the subscription to a specified remote video stream.

public abstract int subscribeRemoteVideoStream(String uid, AliRtcVideoTrack track, boolean sub);

Subscribes to or unsubscribes from the video stream of a specified user.

Note

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

When to call

Call this method before or after joining a channel.

Parameters

Parameter

Type

Description

uid

String

The user ID.

track

AliRtcVideoTrack

The video stream type.

sub

boolean

Specifies whether to subscribe to the video stream of the specified user.

  • true: Subscribe to the video stream.

  • false: Unsubscribe from the video stream.

Return value

  • 0: The call succeeded.

  • A non-zero value: The 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 the parameter to false, the following occurs:

  • The SDK stops subscribing to all remote video streams in the current meeting.

  • New users who join the meeting later will also not be subscribed (even if you have 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 subscribe to the video stream of a specified user.

To resume subscriptions, call this method again and set the parameter to true.

Note

By default, the SDK subscribes to all remote video streams when a user joins a meeting. To disable this default behavior, call setDefaultSubscribeAllRemoteVideoStreams(false) before the user joins the meeting.

Parameters

Parameter

Type

Description

sub

boolean

Specifies whether to stop or resume receiving all remote video streams. Valid values:

  • true (default): Resumes receiving streams.

  • false: Stops receiving streams.

Return value

A return value of 0 indicates that the method call is successful. Any other value indicates that the method call failed.

subscribeRemoteMediaStream[1/2]

Subscribes to or unsubscribes from the media stream of a specific remote user.

public abstract int subscribeRemoteMediaStream(String uid, AliRtcVideoTrack videoTrack, boolean subVideo, boolean subAudio);

This method subscribes to the audio and video streams of a remote user.

Note

In this method, the AliRtcVideoTrackNo parameter of AliRtcVideoTrack is invalid. Setting this parameter has no effect.

Related methods

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

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

videoTrack

AliRtcVideoTrack

The type of the video stream.

subVideo

boolean

Specifies whether to subscribe to the video stream of the remote user. Valid values:

  • true (default): Subscribes to the video stream.

  • false: Unsubscribes from the video stream.

subAudio

boolean

Specifies whether to subscribe to the audio stream of the remote user. Valid values:

  • true (default): Subscribes to the audio stream.

  • false: Unsubscribes from the audio stream.

Return value

Returns 0 if the method is called successfully. A non-zero value indicates a failure.

subscribeRemoteMediaStream[2/2]

Subscribes to or unsubscribes from the audio and video streams of a remote user.

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

This method lets you manage subscriptions for both audio and video streams in a single call.

Related methods

Unlike subscribeRemoteMediaStream[1/2], this method uses the videoTrack and audioTrack parameters to specify the desired subscription status to the SDK in a single call. For example:

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

  • If you want to unsubscribe from the camera stream but keep the microphone, set videoTrack and audioTrack to AliRtcVideoTrackNo and AliRtcAudioTrackMic respectively in the next call.

  • If you want to cancel both, set videoTrack and audioTrack to AliRtcVideoTrackNo and AliRtcAudioTrackNo respectively when you call again.

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

Parameters

Parameter

Type

Description

uid

String

The unique user ID assigned by your app server.

videoTrack

AliRtcVideoTrack

The type of the video stream.

audioTrack

AliRtcAudioTrack

The type of the audio stream.

Return values

  • 0: The operation was successful.

  • <0: The operation failed.

subscribeRemoteDestChannelStream

Subscribes to the stream of a specified user in another channel.

public abstract int subscribeRemoteDestChannelStream(String channelId, String uid, AliRtcVideoTrack track, boolean sub_audio, boolean sub);

Parameters

Parameter

Type

Description

channelId

String

The ID of the remote channel.

uid

String

The ID of the remote user.

track

AliRtcVideoTrack

The video stream to subscribe to.

sub_audio

boolean

Specifies whether to stop or resume pulling the audio stream from the specified remote user. Valid values:

  • true (default): Resume.

  • false: Stop.

sub

boolean

Stops or resumes the cross-channel subscription to the stream of the specified user.

Return value

0 indicates that the method call was successful. Any other value indicates that the call failed.

subscribeRemoteDestChannelAllStream

Stops or resumes subscribing to all user streams from another channel.

public abstract int subscribeRemoteDestChannelAllStream(String channelId, AliRtcVideoTrack track, boolean sub_audio, boolean sub);

Parameters

Parameter

Type

Description

channelId

String

The ID of the remote destination channel.

videoTrack

AliRtcVideoTrack

The type of video stream to subscribe to.

sub_audio

boolean

Specifies whether to subscribe to the audio streams of users in the destination channel.

  • true: Subscribe to the audio streams.

  • false: Unsubscribe from the audio streams.

sub

boolean

Specifies whether to subscribe to or unsubscribe from the streams.

  • true: Subscribe.

  • false: Unsubscribe.

Return value

  • 0: The call succeeded.

  • Any other value: The call failed.

setRemoteAudioVolume

Adjusts the playback volume of the remote audio stream.

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

Use this method to adjust the playback volume of a specified user's audio stream on the local device.

Note

This setting affects only the audio playback on the local device.

Parameters

Parameter

Type

Description

uid

String

The unique ID of a user. This ID is typically assigned by your app server.

volume

int

The playback volume. The value ranges from 0 to 100.

  • 0: Mute.

  • 100: The original volume.

Return value

  • 0: The method call was successful.

  • A non-zero value: The method call failed. For example, the value of the volume parameter is invalid.

muteLocalMic

Stops or resumes sending the local audio stream.

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

When you mute the microphone, the audio stream sends silent frames. The audio capture and encoding modules continue to run.

When to call

Call this method before or after you join a channel.

Callbacks

After a successful call, remote users receive the <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#ea457055e4izi" id="cce3d390a3xud">onUserAudioMuted</a> callback to indicate whether that user is muted.

Parameters

Parameter

Type

Description

mute

boolean

Specifies whether to stop or resume sending the local audio stream. Valid values:

  • true: Mutes the local audio stream by sending silent frames.

  • false (default): Resumes sending the audio stream.

mode

AliRtcMuteLocalAudioMode

The muting mode. The default is microphone muting mode.

Return value

0 indicates that the method call is successful. A value other than 0 indicates that the call has failed. Muting only sends silent frames in the audio stream. The audio capture and encoding modules continue to run.

muteRemoteAudioPlaying

Stops or resumes the playback of a remote audio stream.

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

This API only stops or resumes a specified remote user's audio playback, but it does not affect pulling and decoding the remote audio stream. 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 call this method before or after you join a meeting.

Parameters

Parameter

Type

Description

uid

String

The user ID.

mute

boolean

Specifies whether to stop or resume playing the remote audio stream. Valid values:

  • true: Stop playback.

  • false (default): Resume playback.

Returns

A value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

muteAllRemoteAudioPlaying

Stops or resumes playing all remote audio.

public abstract int muteAllRemoteAudioPlaying(boolean mute);

This method stops or resumes playing all remote audio.

Note

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

When to call

Call this method before or after you join a channel.

Parameters

Parameter

Type

Description

mute

boolean

Specifies whether to stop or resume playing all remote audio. Valid values include the following:

  • true: Stops playback.

  • false (default): Resumes playback.

Return value

0 indicates that the method call was successful. Any other value indicates that the call failed.

startAudioCapture[1/2]

Starts audio capture.

public abstract int startAudioCapture();

You can call this method before joining a meeting to start audio capture in advance. If you do not call this method, the SDK automatically controls the audio capture device. To restart audio capture after stopping it with stopAudioCapture, call this method.

When to call

Call this method before or after joining a meeting.

Related methods

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

Related callbacks

After you call this method to change the local audio capture status, the onLocalAudioStateChanged callback reports the status change.

Return value

A return value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

startAudioCapture[2/2]

Enables audio capture.

public abstract int startAudioCapture(boolean keepAlive);

Muting disables microphone capture.

Use this method to enable audio capture. Call this method before joining a channel to start capture early. If you do not call this method, the SDK automatically manages the audio capture device.

When to call

Call this method before or after joining a channel.

Related methods

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

Related callbacks

After you call this method to change the local audio capture status, the onLocalAudioStateChanged callback provides the status change.

Parameters

Parameter

Type

Description

keepAlive

boolean

The status of the capture device after you leave the channel. Valid values:

  • true: The capture device remains enabled after you leave the channel.

  • false (default): The capture device is disabled after you leave the channel.

Return value

0 indicates the method call was successful. Other values indicate the method call failed.

stopAudioCapture

Stops audio capture.

public abstract int stopAudioCapture();

The SDK enables audio capture by default. Actions such as starting a preview or joining a channel automatically start audio capture. Call this method to stop the audio device from capturing audio.

Related callbacks

After you call this method, the onLocalAudioStateChanged callback reports the change in the local audio capture status.

Return value

0 indicates that the method was called successfully. Any other value indicates that the call failed.

setDefaultAudioRoutetoSpeakerphone

Sets the default audio output to the speakerphone.

public abstract int setDefaultAudioRoutetoSpeakerphone(boolean defaultToSpeakerphone);

This method sets the default audio routing device before you join a channel. You can set the default output to the earpiece or the speakerphone. By default, the software development kit (SDK) uses the speakerphone. To change this default setting, call this method before joining the channel.

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

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

Mobile devices usually have two audio output devices: the earpiece and the speakerphone.

  • Earpiece: The sound is quieter. You must hold the device to your ear to hear clearly. This option provides good privacy and is ideal for phone calls.

  • Speakerphone: The sound is louder. You can hear without holding the device to your face. This enables a hands-free feature.

Related methods

This method modifies the default audio routing setting. The enableSpeakerphone method sets the current routing device.

When to call

Call this method before or after joining a channel.

Parameters

Parameter

Type

Description

defaultToSpeakerphone

boolean

Specifies whether to use the speakerphone as the default audio output.

  • true: Speakerphone mode.

  • false: Earpiece mode.

Return value

  • 0: The method call succeeded.

  • <0: The method call failed.

enableSpeakerphone

Sets the audio output to the earpiece or the speaker.

public abstract int enableSpeakerphone(boolean enable);

Call this method to select the audio playback device, either the earpiece or the speaker, after joining a channel. If you do not call this method, the default audio routing device is used for playback.

The SDK has a predefined audio routing priority. It automatically switches the audio route based on the connection status of peripheral devices. The priority is as follows: Wired headset > Bluetooth headset > User settings > Default settings. Because of this priority, this method call has no effect when a peripheral device is connected. For more information about audio routing settings, see Audio routing settings.

When to call

Call this method before or after joining a channel.

Related methods

<a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#d4dab00b21ebx" id="944fb5797e773">setDefaultAudioRoutetoSpeakerphone</a> is used to modify the default audio routing settings. You can use this API to set the current routing device.

Parameters

Parameter

Type

Description

enable

boolean

The audio output device.

  • true (default): Speaker mode.

  • false: Earpiece mode.

Return value

A return value of 0 indicates that the method call is successful. Any other value indicates that the call has failed.

isSpeakerOn

Checks whether the speaker or the earpiece is used for audio output.

public abstract boolean isSpeakerOn();

Return value

Returns true if the speaker is on. Returns false if the earpiece is on.

enableAudioVolumeIndication

Enables audio volume notifications for users.

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

This method enables the SDK to periodically report volume information. This includes the volume of the local user sending a stream and the remote user with the highest instantaneous volume. To use this feature, implement the AliRtcAudioVolumeObserver class and call the registerAudioVolumeObserver method to register the observer object.

When to call

Call this method before or after you join a channel.

Related callbacks

After a successful call to this method, the SDK triggers the following two callbacks at the specified interval if a user in the channel is sending a stream:

  • The audio volume of the speaker is reported through the AliRtcAudioVolumeObserver#onAudioVolume callback. The callback frequency is determined by the interval parameter.

  • Voice activity detection: The AliRtcAudioVolumeObserver#onActiveSpeaker callback reports the UID of the speaker when an active speaker is detected.

Parameters

Parameter

Type

Description

interval

int

The time interval.

  • Unit: ms.

  • Default value: 300 ms.

  • The value must be 10 ms or greater. A value from 300 ms to 500 ms is recommended. If you set this parameter to 0 or a smaller value, the audio volume and active speaker notifications are disabled.

smooth

int

The smoothing coefficient. A larger value indicates a higher degree of smoothing. A smaller value indicates a lower degree of smoothing and better real-time performance.

  • Default value: 3.

  • Valid values: 0 to 9. A value of 3 is recommended.

reportVad

int

Specifies whether to enable local voice activity detection.

  • 1: Enables the feature. The result is reported through the AliRtcAudioVolumeObserver callbacks.

  • 0 (default): Disables the feature.

Return value

A value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

enableEarBack

Enables in-ear monitoring.

public abstract int enableEarBack(boolean enable);

This method enables or disables the in-ear monitoring feature. For the best experience, use wired or Bluetooth headphones when this feature is enabled.

When to call

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 that the method call is successful. A value other than 0 indicates that the method call failed.

setEarBackVolume

Sets the in-ear monitoring volume.

public abstract int setEarBackVolume(int volume) ;

Use this API to set the in-ear monitoring volume. The setting takes effect only after you enable the in-ear monitoring feature by calling enableEarBack.

When to call

Call this method before or after joining a channel.

Parameters

Parameter

Type

Description

volume

int

The volume. The value ranges from 0 to 100. The default value is 100.

  • 0: Mute.

  • 100: (Default) The original volume.

Return value

  • 0: The method call was successful.

  • <0: The method call failed.

startAudioPlayer

Starts the audio playback device.

public abstract int startAudioPlayer();

Call this method to start audio playback in advance. If you do not call this method, the SDK automatically starts playback after it subscribes to an audio stream.

Returns

  • 0: The call succeeded.

  • A non-zero value: The call failed. The value is an error code.

stopAudioPlayer

Stops the audio playback device.

 public abstract int stopAudioPlayer();

This method lets you stop audio playback and is the counterpart to startAudioPlayer.

Return value

  • 0: The call is successful.

  • A non-zero value: The call failed. An error code is returned.

setPlayoutVolume

Sets the local playback volume.

public abstract int setPlayoutVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

The playback volume. The value ranges from 0 to 400.

  • 0: Mute.

  • 100: Original volume.

  • >100: Amplified volume.

Return value

  • 0: The call was successful.

  • A non-zero value: The call failed.

setRecordingVolume

Sets the recording volume.

public abstract int setRecordingVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

The recording volume. The value ranges from 0 to 400.

  • 0: Mutes the audio.

  • 100: The original volume.

  • >100: Increases the volume.

Return value

  • 0: The call succeeded.

  • A non-zero value: The call failed.

playAudioFileTest

Plays an audio file.

public abstract int playAudioFileTest(String filePath) ;

Use this method to play an audio file to test audio playback before you join a meeting.

When to call

Call this method only before joining a meeting.

Limitations

Each call to this method overwrites the previous one. A new call also stops any audio file that is currently playing.

Parameters

Parameter

Type

Description

filePath

String

The file path.

Return value

  • 0: The call is successful.

  • A non-zero value: The call failed.

stopAudioFileTest

Stops the audio file playback.

public abstract int stopAudioFileTest();

This method is the counterpart to playAudioFileTest. It stops the audio file playback.

Limitations

Call this method only before joining a channel.

Return value

  • 0: The call succeeded.

  • A non-zero value: The call failed.

startAudioCaptureTest

Starts the audio capture device test before a call.

public abstract int startAudioCaptureTest();

This method starts a test to check if the local audio capture device works correctly before a call. After this method is called, the SDK reports the volume of the capture device to the developer through the AliRtcAudioVolumeObserver::OnTestAudioVolume callback.

When to call

Call this method before joining a channel. After the test is complete, call stopAudioCaptureTest to stop the device test and prevent the device from being occupied.

Return value

  • 0: The call is successful.

  • A non-zero value: The call failed. The value is an error code.

stopAudioCaptureTest

Stops the audio capture device test.

public abstract int stopAudioCaptureTest();

You must call this method to stop the audio capture test after you call startAudioCaptureTest.

When to call

Call this method before joining a channel.

Return value

  • 0: The call was successful.

  • A non-zero value: The call failed. An error code is returned.

setAudioEffectVoiceChangerMode

Sets the voice changer mode.

public abstract int setAudioEffectVoiceChangerMode(AliRtcAudioEffectVoiceChangerMode mode);

Parameters

Parameter

Type

Description

mode

AliRtcAudioEffectVoiceChangerMode

The voice changer mode. The default value is AliRtcSdk_AudioEffect_Voice_Changer_OFF (Off).

Return value

A value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

setAudioEffectPitchValue

Sets the pitch parameter.

public abstract int setAudioEffectPitchValue(double value);

Parameters

Parameter

Type

Description

value

double

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

Return value

A value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

setAudioEffectReverbMode

Sets the reverb sound effect mode.

public abstract int setAudioEffectReverbMode(AliRtcAudioEffectReverbMode mode);

Parameters

Parameter

Type

Description

mode

AliRtcAudioEffectReverbMode

The sound effect reverb mode. The default value is AliRtcAudioEffectReverb_Off (Off).

Returns

A return value of 0 indicates that the method call succeeded. Any other value indicates that the call failed.

setAudioEffectReverbParamType

Sets the type and parameters for the reverb sound effect.

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

Parameters

Parameter

Type

Description

type

AliRtcAudioEffectReverbParamType

The reverb parameter for the sound effect.

value

float

The value of the parameter.

Return value

A return value of 0 indicates a successful call. Any other value indicates a failed call.

addExternalAudioStream

Adds an external audio stream.

public abstract int addExternalAudioStream(AliRtcExternalAudioStreamConfig config);

Use this method to add an external audio stream. The steps are as follows:

  1. Call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#42b363024fich" id="20c33a9acb0ui">addExternalAudioStream</a> 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, call <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#0333f86114078" id="16d826dedcli6">removeExternalAudioStream</a> to remove the external audio stream.

To publish custom-captured audio in a channel, see Custom Audio Capture.

Parameters

Parameter

Type

Description

config

AliRtcExternalAudioStreamConfig

External audio stream configuration.

Return value

A return value greater than 0 indicates a successful call and is the ID of the external audio stream. Any other value indicates that the call failed.

pushExternalAudioStreamRawData

Pushes raw data to an external audio stream.

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

Use this method to push data to a specified audio stream. The steps are as follows:

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

  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 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="106c7aefa27c0">removeExternalAudioStream</a> to remove the external audio stream.

For more information, see Custom audio capture.

When to call

Call this method after you join a channel.

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream.

rawData

AliRtcAudioFrame

The audio data.

Return value

0 indicates that the method was called successfully. Any other value indicates that the call failed.

setExternalAudioStreamPublishVolume

Sets the publish volume for an external audio stream.

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

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream.

publishVolume

int

The publish volume. The value ranges from 0 to 100.

Return value

A return value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

getExternalAudioStreamPublishVolume

Gets the stream ingest volume for an external audio stream.

public abstract int getExternalAudioStreamPublishVolume(int streamId);

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream.

Return value

The stream ingest volume, which ranges from 0 to 100. A value of < 0 indicates that the call failed.

setExternalAudioStreamPlayoutVolume

Sets the playback volume of an external audio stream.

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

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream.

playoutVolume

int

The playback volume. The value ranges from 0 to 100.

Return value

Returns 0 on success, or a non-zero value on failure.

getExternalAudioStreamPlayoutVolume

Gets the playback volume of an external audio stream.

public abstract int getExternalAudioStreamPlayoutVolume(int streamId);

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream.

Return value

The playback volume. The value ranges from 0 to 100. A value < 0 indicates that the call failed.

removeExternalAudioStream

Removes an external audio stream.

public abstract int removeExternalAudioStream(int streamId);

This method removes the external audio stream that corresponds to the specified streamId. This method is the counterpart to the addExternalAudioStream method.

When to call

To use the custom audio input feature, call the addExternalAudioStream method to add an audio stream and get its ID. Then, call the pushExternalAudioStreamRawData method to push audio data to the SDK. To stop the custom audio input, call this method to remove the corresponding external audio stream and release resources.

Parameters

Parameter

Type

Description

streamId

int

The ID of the external audio stream. This ID is the return value of a successful call to the addExternalAudioStream method.

Return values

  • 0: The call was successful.

  • <0: The call failed. An error code is returned.

getAudioFileInfo

Gets audio file information.

public abstract int getAudioFileInfo(String fileName);

You can call this method to obtain the duration of an audio file asynchronously. The information is returned through the onAudioFileInfo callback.

Parameters

Parameter

Type

Description

fileName

String

The path of the audio file.

Return value

  • 0: The call was successful.

  • A non-zero value: An error code.

startAudioAccompany

Starts audio accompaniment mixing.

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

This method plays local or online accompaniment files. This is an asynchronous call. After calling this method, listen for the accompaniment playback status through the AliRtcEngineNotify#onAudioAccompanyStateChanged callback.

When to call

Call this method after joining a channel.

Limitations

Unlike sound effects, only one accompaniment can be played at a time. Calling this method again overwrites the previous accompaniment.

Parameters

Parameter

Type

Description

fileName

String

The path of the accompaniment file.

config

AliRtcAudioAccompanyConfig

The configuration for accompaniment playback. This includes settings such as local-only playback, microphone audio replacement, loop count, start position, and volume.

Return value

  • 0: The call was successful.

  • A non-zero value: The call failed. An error code is returned.

stopAudioAccompany

Stops the audio accompaniment.

public abstract int stopAudioAccompany() ;

This method is the counterpart to startAudioAccompany and stops accompaniment playback.

When to call

Call this method before or after you join a channel.

Return values

  • 0: The call succeeded.

  • A non-zero value: The call failed. The return value is the error code.

setAudioAccompanyVolume

Sets the volume of the audio accompaniment, including the local playback volume and the stream ingest volume.

public abstract int setAudioAccompanyVolume( int volume) ;

Call this method to set the volume of the audio accompaniment. This method sets both the local playback volume and the stream ingest volume. In contrast, setAudioAccompanyPlayoutVolume sets only the local playback volume, and setAudioAccompanyPublishVolume sets only the stream ingest volume.

Parameters

Parameter

Type

Description

volume

int

The volume of the audio accompaniment. The value ranges from 0 to 100.

0: Mute.

100: The original volume of the file.

Return value

  • 0: The call succeeded.

  • A non-zero value: The call failed and an error code is returned.

setAudioAccompanyPublishVolume

Sets the volume of the audio accompaniment for stream ingest.

public abstract int setAudioAccompanyPublishVolume(int volume) ;

Parameters

Parameter

Type

Description

volume

int

The volume of the audio accompaniment. The value ranges from 0 to 100.

0: Mute.

100: The original volume of the file.

Return value

  • 0: The call is successful.

  • A non-zero value: The call failed. An error code is returned.

getAudioAccompanyPublishVolume

Gets the stream ingest volume of the audio accompaniment.

public abstract int getAudioAccompanyPublishVolume() ;

Return value

The stream ingest volume of the accompaniment music.

  • [0-100]: Success.

  • Other: An error code.

setAudioAccompanyPlayoutVolume

Sets the local playback volume for the audio accompaniment.

public abstract int setAudioAccompanyPlayoutVolume(int volume) ;

Parameters

Parameter

Type

Description

volume

int

The volume of the audio accompaniment. Valid values range from 0 to 100.

0: Mute.

100: The original volume of the file.

Return value

  • 0: The call succeeded.

  • A non-zero value: The call failed and an error code is returned.

getAudioAccompanyPlayoutVolume

Gets the local playback volume of the audio accompaniment.

public abstract int getAudioAccompanyPlayoutVolume() ;

Return value

The local playback volume of the audio accompaniment.

  • A value from 0 to 100 indicates a successful call.

  • Other values indicate an error code.

pauseAudioAccompany

Pauses the audio accompaniment mixing.

public abstract int pauseAudioAccompany();

Return value

  • 0: The call was successful.

  • A non-zero value: The call failed. The value is the error code.

resumeAudioAccompany

Resumes audio accompaniment mixing.

public abstract int resumeAudioAccompany();

Return value

  • 0: The call is successful.

  • A non-zero value: The call failed. 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: The duration of the accompaniment file.

  • <0: The call failed and an error code is returned.

getAudioAccompanyCurrentPosition

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

public abstract int getAudioAccompanyCurrentPosition();

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

Returns

  • >= 0: The playback progress of the audio accompaniment file.

  • < 0: The call failed. An error code is returned.

setAudioAccompanyPosition

Sets the playback position of the accompaniment file.

public abstract int setAudioAccompanyPosition(int posMs);

This method sets the playback progress of the accompaniment. Use this method to implement features such as dragging a progress bar. After a successful call, the accompaniment file starts playback from the position that is specified by posMs.

Parameters

Parameter

Type

Description

posMs

int

The playback position in milliseconds.

Return value

  • 0: Success.

  • A non-zero value: 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.

filePath

String

The path of the sound effect file.

Return value

0 indicates that the method call was successful. Other values indicate that the call failed.

unloadAudioEffect

Unloads 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.

Return value

Returns 0 if the method is called successfully. Returns a non-zero value if the call fails.

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 user-specified ID for the sound effect file.

filePath

String

The path of the sound effect file.

cycles

int

The number of playback loops. A value of -1 indicates an infinite loop.

publish

boolean

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

  • true: The sound effect is published to remote users.

  • false (Default): The sound effect is played for the local user only.

Return value

A value of 0 indicates that the method call succeeded. Any other value indicates that the call failed.

stopAudioEffect

Stops playing a sound effect.

public abstract int stopAudioEffect(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file.

Return value

Returns 0 on success, or a non-zero value on failure.

stopAllAudioEffects

Stops playing all sound effects.

public abstract int stopAllAudioEffects();

Return value

Returns 0 on success, or a non-zero value on failure.

setAudioEffectPublishVolume

Sets the stream ingest volume for a sound effect.

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

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file.

volume

int

The mixing volume. The value ranges from 0 to 100. The default value is 50.

Return value

A value of 0 means the method call succeeded. Any other value means it failed.

getAudioEffectPublishVolume

Gets the volume of a sound effect for stream ingest.

public abstract int getAudioEffectPublishVolume(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID that you assign to the sound effect file.

Return values

A value of 0 indicates that the method call succeeded. Any other value indicates that the call failed.

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 of the sound effect.

volume

int

The playback volume. The value ranges from 0 to 100. The default value is 50.

Return value

A value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

getAudioEffectPlayoutVolume

Gets the local playback volume of a sound effect on Android and iOS.

public abstract int getAudioEffectPlayoutVolume(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID that you assign to the sound effect file.

Return value

A return value of 0 indicates success. Any other value indicates failure.

setAllAudioEffectsPublishVolume

Sets the publish mixing volume for all sound effects.

public abstract int setAllAudioEffectsPublishVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

The mixing volume. The value ranges from 0 to 100. The default value is 50.

Return value

Returns 0 if the method call succeeds. Returns another value if the call fails.

setAllAudioEffectsPlayoutVolume

Sets the local playback volume for all sound effects on Android and iOS.

public abstract int setAllAudioEffectsPlayoutVolume(int volume);

Parameters

Parameter

Type

Description

volume

int

The playback volume. The value ranges from 0 to 100. The default value is 50.

Return value

A value of 0 indicates that the method call succeeded. Any other value indicates that the call failed.

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

The record type.

recordFormat

AliRtcRecordFormat

The format type, such as wav, aac, or mp4.

filePath

String

The recording file name.

audioConfig

AliRtcRecordAudioConfig

The audio configuration.

videoConfig

AliRtcRecordVideoConfig

The video configuration.

maxSize

long

The maximum file size.

maxDuration

long

The maximum file duration.

Return value

Returns true if the operation is successful, or false otherwise.

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

  • When you record an audio stream, the recording file contains the mixed audio of the local stream and all remote streams.

stopRecord

Stops recording the 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 of the sound effect file.

Return value

A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

pauseAllAudioEffects

Pauses all sound effects.

public abstract int pauseAllAudioEffects();

Return value

0 indicates that the method call succeeded. Any other value indicates that the method call failed.

resumeAudioEffect

Resumes the playback of a sound effect.

public abstract int resumeAudioEffect(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID that you assign to the sound effect file.

Return value

A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

resumeAllAudioEffects

Resumes playing all sound effects.

public abstract int resumeAllAudioEffects();

Return value

0 indicates that the method call was successful. Any other value indicates that the call failed.

createRenderSurfaceView

Creates a SurfaceView for rendering.

public abstract SophonSurfaceView createRenderSurfaceView(Context context);

To display a video view, call this method instead of creating a SurfaceView directly. Call it as follows:

  • Assign the return value to AliRtcVideoCanvas#view.

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

When to call

Call this method before or after joining a channel.

Limitations

Call this method on the main thread.

Parameters

Parameter

Type

Description

context

Context

The context of the Android activity.

setLocalViewConfig

Sets the rendering window and parameters for the local preview.

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

This method sets the local preview view. It attaches a display window (view) to the local video stream and sets the rendering mode, mirror mode, and rotation angle for the local user's view. These settings affect only the local preview and not the published video stream. To set the view for a remote user, call setRemoteViewConfig.

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

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

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

  • Explicitly call startPreview() to start the local preview.

When to call

This method can be called before or after joining a channel.

Parameters

Parameter

Type

Description

viewConfig

AliRtcVideoCanvas

Rendering parameters, which include the rendering window and rendering mode.

track

AliRtcVideoTrack

The type of the video stream.

Returns

Returns 0 if the method call is successful. Returns a non-zero value if the call fails.

setRemoteViewConfig

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

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. It also sets parameters for the remote view's local display, such as the rendering mode, mirror mode, and rotation angle. These settings only affect the video image that the local user sees. To set the local preview view, call setLocalViewConfig.

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

  • To reset the renderMode parameter of AliRtcVideoCanvas during playback, modify only the renderMode value. Keep all other parameters unchanged.

  • To reset the mirrorMode parameter of AliRtcVideoCanvas during playback, modify only the mirrorMode value. Keep all other parameters unchanged.

When to call

Call this method when you receive the onRemoteTrackAvailableNotify callback. This callback is triggered when a video stream from a remote user becomes available.

Parameters

Parameter

Type

Description

canvas

AliRtcVideoCanvas

Rendering parameters, which include the rendering window and method.

uid

String

The user ID.

track

AliRtcVideoTrack

The type of the video stream to set.

Return value

A return value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

setCameraCapturerConfiguration

Sets the camera capture preferences.

public abstract int setCameraCapturerConfiguration(AliEngineCameraCapturerConfiguration cameraCapturerConfiguration);

Use this method to configure camera capture preferences, such as the camera direction and capture frame rate.

When to call

Call this method before opening the camera, for example, before calling the following methods:

  • startPreview

  • joinChannel

Parameters

Parameter

Type

Description

cameraCapturerConfiguration

AliEngineCameraCapturerConfiguration

The camera capture preferences, including the camera direction and frame rate. The default values are as follows:

  • preference:

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_AUTO: The SDK automatically adjusts the capture parameters.

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_PREVIEW: High-definition preview. The capture process prioritizes video preview quality.

    • ALIRTC_CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE: The capture process selects the resolution that is closest to the stream ingest to prioritize device performance.

  • cameraDirection: AliRtcCameraDirection.CAMERA_FRONT. The front camera is used by default.

  • fps: -1 indicates that the internal frame rate setting of the encoder is used. The default value is 15.

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

  • disableVideoCaptureReverse: Specifies whether to flip captured video frames based on the aspect ratio. -1: Default. 0: Disabled. 1: Enabled.

  • captureObserverOriginal: Specifies whether to use a callback for the original videoframe data. -1: Default. 0: Disabled. 1: Enabled.

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

  • cameraTextureCapture: Specifies whether to enable texture capture for the camera. -1: Default. 0: Disabled. 1: Enabled.

For the preceding parameters, a value of -1 indicates that the default SDK settings are used.

Return value

Returns 0 if the method call is successful. Otherwise, an error code is returned.

enableLocalVideo

Disables or enables local video capture.

public abstract int enableLocalVideo(boolean enable);

This method controls local video capture. When local video capture is disabled, video data is unavailable for local preview and stream ingest. This does not affect receiving remote video. If you call this method to disable the local camera, the local preview and stream ingest freeze on the last captured frame.

Note

Local video capture is enabled by default in the SDK.

When to call

You can call this method before or after you join a channel.

Related callbacks

A successful call to this method triggers the onUserVideoEnabled callback to notify remote users.

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to disable or enable local video capture. Valid values:

  • true (default): Enable.

  • false: Disable.

Returns

A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

muteLocalCamera

Stops or resumes sending local video data.

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

Call this method during stream ingest to send black video frames. The local preview remains normal. The capture, encoding, and sending modules continue to work, but the video content consists of 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 video collection or data transmission processes. To stop 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> to stop collection.

Parameters

Parameter

Type

Description

mute

boolean

Specifies whether to stop or resume sending local video data. Valid values:

  • true: Stops sending.

  • false (default): Resumes sending.

track

AliRtcVideoTrack

The type of the video stream whose publishing status will be changed.

Return value

0 is returned if the method call is successful.

isCameraOn

Checks if the camera is on.

public abstract boolean isCameraOn();

Return value

Returns true if the camera is on, or false if the camera is off.

setVideoEncoderConfiguration

Sets the video encoding properties.

public abstract void setVideoEncoderConfiguration(AliRtcVideoEncoderConfiguration config);

This method sets the video parameters for video stream encoding, such as resolution, frame rate, bitrate, and video orientation. Call this method in all video scenarios.

Note

All parameters have range limits. If a parameter is set outside its valid range, the software development kit (SDK) automatically adjusts it.

When to call

This method can be called before or after joining a channel. To set the camera stream encoding properties only once for each session, call this method before joining the channel.

Limitations

Both the mirrorMode parameter of this method and the setVideoMirrorMode method can set the mirror mode for stream ingest. Use only one of these methods. Using both at the same time can cause the mirror effects to overlap, which may lead to configuration failure or errors.

Parameters

Parameter

Type

Description

config

AliRtcVideoEncoderConfiguration

The predefined encoding properties. Default values:

  • dimensions: [640,480]. The maximum resolution is 1920x1080.

  • frameRate: 15

  • bitrate: 0. This value indicates that the SDK calculates a suitable encoding bitrate based on the video resolution and frame rate.

  • keyFrameInterval: The keyframe interval in milliseconds. The default value is 0, which indicates that the interval is controlled by the SDK.

  • forceStrictKeyFrameInterval: Specifies whether to force the encoder to generate keyframes at the specified interval. The default value 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 that the default SDK setting is used.

setVideoDecoderConfiguration

Sets the video decoding properties.

    public abstract void setVideoDecoderConfiguration(AliRtcVideoDecoderConfiguration config);

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

When to call

Call this method before joining a channel.

Parameters

Name

Type

Description

config

AliRtcVideoDecoderConfiguration

The predefined decoding properties. The default values are as follows:

  • codecType: AliRtcVideoCodecTypeDefault. The decoding type. This includes software decoding, hardware decoding, and hardware texture decoding.

  • enableDecoderBframe: -1. Specifies whether to use B-frames. Enabling this option adds a buffer queue to the decoder and increases latency. If the sender enables B-frames, you must also enable this option to decode the video.

  • textureBindContext: -1. Specifies whether to bind a context for texture decoding.

A value of -1 indicates that the default SDK settings are used.

switchCamera

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

public abstract int switchCamera();

This method lets you dynamically switch cameras while the app is running based on their availability. You do not need to restart the video stream or reconfigure the video source.

When to call

Call this method after the camera is successfully started.

Call restrictions

Available only on Android and iOS platforms.

Return value

A value of 0 indicates that the call is successful. A value other than 0 indicates that the call fails.

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 an invalid state.

Note

Call this method after you turn on the camera. Otherwise, the method returns CAMERA_INVALID(-1).

startPreview

Starts the local video 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 automatically stops the local preview. If you are not publishing the camera stream, the camera also turns off automatically.

When to call

  • Before calling this method, set a view for the local preview by calling setLocalViewConfig. Otherwise, the preview cannot be displayed. This does not affect stream ingest.

  • If needed, call this method to start the preview before you join a channel by calling joinChannel. The camera turns on automatically.

Return value

A return value of 0 indicates that the method call was successful. Any other value indicates that the call failed.

stopPreview

Stops the local preview.

public abstract int stopPreview();

This method stops the local video preview and shuts down the camera. After the preview stops, the local display remains on the last frame. This does not affect stream ingest.

Note

Calling leaveChannel automatically stops the local preview. If you are not publishing the camera stream, the camera is also automatically shut down.

When to call

Call this method to stop the preview after it starts.

Return value

0 indicates that the method was called successfully. Any other value indicates that the call failed.

setCameraZoom

Sets the camera zoom factor.

public abstract int setCameraZoom(float zoom);

This method sets the zoom factor of the camera.

Restrictions

This method is available only on iOS and Android.

When to call

This method takes effect only after the camera is turned on. The zoom factor is reset each time the camera is restarted.

Parameters

Parameter

Type

Description

zoom

float

The camera zoom factor. The value ranges from 1 to the maximum zoom factor that the camera supports. Call GetCameraMaxZoomFactor to obtain the maximum zoom factor that the current device supports.

Return value

  • 0: The call succeeded.

  • A non-zero value: The call failed.

GetCameraMaxZoomFactor

Gets the maximum zoom factor supported by the camera.

public abstract float GetCameraMaxZoomFactor();

Returns

The maximum zoom factor supported by the camera.

GetCurrentZoom

Gets the current zoom setting of the camera.

public abstract float GetCurrentZoom();

Return value

The current zoom ratio of the camera.

SetExposure

Sets the camera exposure.

public abstract int SetExposure(float exposure);

Ambient light that is too dim or too bright affects the quality of captured video. To get better video results, use this method to adjust the exposure of the camera in use. You can call GetMinExposure and GetMaxExposure to get the exposure range that the device supports.

Parameters

Parameter

Type

Description

exposure

float

The exposure value for the camera. The default value is 0, which means the camera's default exposure is used. A larger value results in a higher exposure. If the video image is overexposed, decrease the exposure coefficient. If the video image is underexposed and loses details in dark areas, increase the exposure coefficient. If the specified exposure value is outside the range supported by the device, the SDK automatically adjusts the value.

Returns

  • 0: The method call was successful.

  • A non-zero value: The method call failed.

GetCurrentExposure

Gets the camera exposure.

public abstract float GetCurrentExposure();

Gets the exposure setting of the camera that is currently in use.

Return value

The current camera exposure.

GetMinExposure

Gets the minimum exposure of the camera.

public abstract float GetMinExposure();

Return value

The minimum exposure of the camera.

GetMaxExposure

Gets the maximum exposure that the camera supports.

public abstract float GetMaxExposure();

Return value

The maximum exposure of the camera.

setCameraFlash

Turns the camera flash on or off.

public abstract int setCameraFlash(boolean flash);

Turn the flash on or off.

Note

Usually, only the rear camera has a flash feature.

Limitations

This interface is available only on iOS and Android.

Parameters

Parameter

Type

Description

flash

boolean

Specifies whether to turn the flash on or off.

  • true: Turns the flash on.

  • false: Turns the flash off.

Return value

  • 0: The operation is successful.

  • A non-zero value: The operation failed.

isCameraFocusPointSupported

Checks whether the current device supports manual focus.

public abstract boolean isCameraFocusPointSupported();

Call this method to check whether a focus point can be set on the current camera to support the manual focus feature.

Limitations

This API is available only on iOS and Android.

Return value

  • true: The device supports the manual focus feature.

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

isCameraExposurePointSupported

Checks whether the device supports setting a camera exposure point.

public abstract boolean isCameraExposurePointSupported();

Call this method to check if the current device supports setting an exposure point.

Limitations

This method is available only on iOS and Android.

Return value

  • true: The device supports setting a camera exposure point.

  • false: The device does not support setting a camera exposure point.

setCameraFocusPoint

Sets the manual focus point for the camera.

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

Sets the focus point for the current camera. When you call this method, the camera adjusts the exposure for the specified point once and then maintains that focus value. Before you call this method, call isCameraFocusPointSupported to check whether the device supports the manual focus feature.

Limitations

This method is available only on iOS and Android.

Parameters

Parameter

Type

Description

x

float

The x-axis coordinate value.

y

float

The y-axis coordinate value.

Return value

  • 0: The method call was successful.

  • A non-zero value: The method call failed.

setCameraExposurePoint

Sets the camera exposure point.

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

Calling this method triggers a one-time exposure adjustment for the specified point. The camera then maintains this exposure value. Before you call this method, call isCameraExposurePointSupported to check if the device supports manually setting the exposure point.

Limitations

This method is available only on iOS and Android.

Parameters

Parameter

Type

Description

x

float

The x-axis coordinate.

y

float

The y-axis coordinate.

Return value

  • 0: The call was successful.

  • A non-zero value: The call failed.

isCameraAutoFocusFaceModeSupported

Checks whether the camera supports automatic facial focus.

public abstract boolean isCameraAutoFocusFaceModeSupported();

Checks whether the camera supports automatic facial focus.

When to call

Call this method after the camera is on. This method returns false by default if the camera is off. It returns true if the camera is on and supports both facial recognition and focus features.

Restrictions

This method is available only on iOS and Android.

Return values

  • true: Automatic facial focus is supported.

  • false: Automatic facial focus is not supported.

setCameraAutoFocusFaceModeEnabled

Sets the face-based autofocus for the camera.

public abstract boolean setCameraAutoFocusFaceModeEnabled(boolean enable);

This method sets the camera to focus on faces in real time. Before calling this method, call isCameraAutoFocusFaceModeSupported to check if the device supports this feature.

Limitations

This method is available only on iOS and Android.

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to enable or disable the face-based autofocus feature.

  • true: Enable the feature.

  • false: Disable the feature.

Return value

  • true: The call was successful.

  • false: The call failed.

setVideoMirrorMode

Configures video mirroring.

public abstract int setVideoMirrorMode(AliRtcVideoPipelineMirrorMode mirrorMode);

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

Note

This method has a higher priority than setLocalViewConfig and setVideoEncoderConfiguration. To set the video mirror mode, call this method.

When to call

Call this method before or after joining a channel. The SDK records the setting and applies it to the video when preview and encoding for stream ingest are available.

Limitations

The functionality of this method overlaps with the mirrorMode parameter in setLocalViewConfig&setVideoEncoderConfiguration. Use only one of these methods.

Parameters

Parameter

Type

Description

mirrorMode

AliRtcVideoPipelineMirrorMode

The mirror mode.

Return values

  • 0: The operation is successful.

  • <0: The operation failed.

    • AliRtcErrInner: An internal SDK status error occurred. Check whether the SDK instance was created.

setCapturePipelineScaleMode

Sets the timing for video capture scaling.

public abstract void setCapturePipelineScaleMode(AliRtcCapturePipelineScaleMode mode);

Sets whether to scale the video data immediately upon capture or during encoding. For example, if the capture resolution differs from the encoding resolution, setting the scaling timing determines whether the preview data is consistent with the published stream data.

When to call

Call this method before you open the camera, such as before you call startPreview or joinChannel.

Parameters

Parameter

Type

Description

mode

AliRtcCapturePipelineScaleMode

The mode that controls the timing for capture scaling. By default, scaling is performed 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

Specifies whether to enable the external video input source.

  • true: Enable.

  • false (default): Disable.

useTexture

boolean

Specifies whether to use the texture mode.

  • true: Use.

  • false (default): Do not use.

type

AliRtcVideoTrack

The video stream type.

renderMode

AliRtcRenderMode

The rendering mode.

pushExternalVideoFrame

Inputs video data.

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

Parameters

Parameter

Type

Description

aliRawDataFrame

AliRtcRawDataFrame

Frame data.

streameType

AliRtcVideoTrack

The video stream type.

Returns

0 if the method call is successful. A non-zero value if the call fails.

startPublishLiveStream

Starts a bypass live stream.

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

Parameters

Parameter

Type

Description

streamUrl

String

Ingest URL.

transcodingParam

AliRtcLiveTranscodingParam

Stream ingest parameters.

Return value

A return value of 0 indicates that the method was called successfully. Any other value indicates that the call failed.

updatePublishLiveStream

Updates the parameters for bypass live streaming.

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

Parameters

Parameter

Type

Description

streamUrl

String

The ingest URL.

transcodingParam

AliRtcLiveTranscodingParam

The stream ingest parameters.

Return value

Returns 0 if the method is called successfully. Returns a non-zero value if the method call fails.

stopPublishLiveStream

Stops bypass live streaming.

public abstract int stopPublishLiveStream(String streamUrl);

Parameters

Parameter

Type

Description

streamUrl

String

The ingest URL.

Return value

Returns 0 if the method is called successfully. Returns a non-zero value if the call fails.

getPublishLiveStreamState

Gets the status of the bypass live stream.

public abstract AliRtcEngine.AliRtcLiveTranscodingState getPublishLiveStreamState(String streamUrl);

Parameters

Parameter

Type

Description

streamUrl

String

The ingest URL for the bypass live stream.

Return value

The status of the bypass live stream.

startNetworkQualityProbeTest

Starts a network quality probe test.

public abstract int startNetworkQualityProbeTest(AlirtcNetworkQualityProbeConfig config);

Parameters

Parameter

Type

Description

config

AlirtcNetworkQualityProbeConfig

The probe configuration parameters.

Return value

0 indicates success. Other values indicate failure.

stopNetworkQualityProbeTest

Stops the network quality probe test.

public abstract int stopNetworkQualityProbeTest();

Return value

A return value of 0 indicates success. Any other value indicates that the operation failed.

sendMediaExtensionMsg

Sends media extension messages.

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

The SDK lets you send and receive media extension messages. This method sends the messages using the Supplemental Enhancement Information (SEI) extension protocol. The receiver receives the messages by listening for the onMediaExtensionMsgReceived callback.

Common scenarios include the following:

  • Use media extension messages to send timestamps. This helps calculate end-to-end network latency or synchronize data with other services.

  • Use media extension messages to send descriptive information. You can send up to 4 KB of data. This is useful for small amounts of data. Use JSON or plain strings for the data format.

When to call

Call this method after you start stream ingest.

Limits

Media extension messages reuse the audio and video data tunnel. Because of this, you must control the frequency and length of custom messages. The limits are as follows:

  • You can send a maximum of `fps` messages per second, as set in the profile. This is because SEI information is transmitted within the H.264/H.265 stream and can be attached only when video frames are encoded.

  • The size of a custom message body is limited to 4 KB to prevent any impact on media data transmission quality. Custom messages are designed for transmitting small amounts of information.

  • In the sendMediaExtensionMsg function, the repeatCount parameter specifies the degree of redundancy for the custom message. If its value is greater than 1, the message is sent multiple times,

  • This repetition helps prevent message loss from network packets. However, other users in the channel will receive the same message multiple times. Remove these duplicate messages.

  • Subscribers in the channel also receive custom messages during a bypass live stream.

  • Only one `MediaExtensionMsg` can be in transit at a time. If you call `sendMediaExtensionMsg` multiple times, the new data overwrites the previous data.

Related callbacks

When the stream ingest client sends a media extension message, the stream pulling client receives the message by listening for the onMediaExtensionMsgReceived callback.

Parameters

Parameter

Type

Description

message

byte[]

The media extension message. The maximum length is 4 KB.

repeatCount

int

The number of repetitions. This represents message redundancy to prevent message loss from network packet loss. A value of -1 means the message is sent indefinitely.

delay

int

The delay in milliseconds. This is the minimum time in milliseconds before the extension message is sent after the API call.

isKeyFrame

boolean

Specifies whether to attach the extension message only to keyframes. A value of `true` means the message is attached only to keyframes.

Return values

  • 0: The call is successful.

  • <0: The call failed. An error code is returned.

    • ERR_INNER(-1): An internal SDK error occurred. This can happen if the SDK is not initialized or if the method is called after the SDK is destroyed.

sendMediaExtensionMsgEx

Sends media extension messages.

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

The SDK lets you send and receive media extension messages. This method sends media extension messages using the Supplemental Enhancement Information (SEI) extension protocol. The receiver can get the message by listening for the onMediaExtensionMsgReceived callback. If you set payloadType to 5, this method works the same as the sendMediaExtensionMsg method.

Common scenarios include the following:

  • Use media extension messages to pass timestamps, calculate end-to-end network latency, or synchronize data with other services.

  • Use media extension messages to pass descriptive information. You can pass up to 4 KB of data, which is useful for transmitting small amounts of information. Use JSON or plain strings for the data.

When to call

Call this method after you start stream ingest.

Limits

Media extension messages reuse the audio and video data tunnel. Therefore, control the frequency and length of custom messages. The limits are as follows:

  • A maximum of `fps` messages are sent per second, as set in the profile. This is because SEI messages are transmitted in the H.264/H.265 stream, and extension information can be attached only when video frames are encoded.

  • A maximum of `fps` messages are sent per second, as set in the profile. This is because SEI messages are transmitted in the H.264/H.265 stream, and extension information can be attached only when video frames are encoded.

  • To ensure media data transmission quality, the size of a custom message body is limited to 4 KB. This size is suitable for transmitting small amounts of information.

  • The `repeatCount` parameter sets the message redundancy. If this value is greater than 1, the message is sent multiple times to prevent loss from network packet loss. Other subscribers in the channel will receive the same message multiple times, so you must remove the duplicates.

  • Subscribers in the channel also receive custom messages during bypass live streaming.

  • Only one media extension message can be in transit at a time. If you call `sendMediaExtensionMsg` multiple times, the new data overwrites the previous data.

Parameters

Parameter

Type

Description

message

byte[]

The media extension message. The maximum length is 4 KB.

repeatCount

int

The number of repetitions. This represents message redundancy and prevents message loss from network packet loss. A value of -1 means the message is sent indefinitely.

delay

int

The delay in milliseconds. This is the minimum time before the extension message is sent after the API is called.

isKeyFrame

boolean

Specifies whether to attach the extension message only to keyframes. A value of `true` indicates that the message is attached only to keyframes.

payloadType

int

The valid range is [5, 100..254]. If you set this parameter to 5, this method works the same as the `sendMediaExtensionMsg` method.

Returns

  • 0: The call is successful.

  • <0: The call failed. An error code is returned.

    • ERR_INNER(-1): An internal SDK error occurred. Possible causes include calling the method before the SDK is initialized or after it is destroyed.

onConnectionStatusChange

A callback for the network connection status. You must handle this callback.

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

Parameters

Parameter

Type

Description

status

AliRtcConnectionStatus

The current network connection status.

reason

AliRtcConnectionStatusChangeReason

The reason for the network connection status change.

OnLocalDeviceException

This is the callback for a local device exception. You must handle this callback.

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

Parameters

Parameter

Type

Description

deviceType

AliRtcEngineLocalDeviceType

The device type.

exceptionType

AliRtcEngineLocalDeviceExceptionType

The device exception type.

msg

String

Information about the exception.

onAuthInfoWillExpire

This callback notifies you that the user authentication information will expire in 30 seconds. You must handle this callback.

public void onAuthInfoWillExpire();

When you receive this callback, the authentication expires in 30 seconds. Obtain a new token, and then update the authentication information in one of the following ways:

  • Call the <a baseurl="t2309760_v6_4_1.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#975b9af9ecq1a" id="8099ac5a509hn">refreshAuthInfo</a> method 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 authentication information expires. After you receive this callback, update the authentication information promptly.

onAuthInfoExpired

When a user calls an API that requires authentication, the server returns a message indicating that the authentication information has expired.

public void onAuthInfoExpired();

This callback indicates that the authentication information has expired. To remain in the channel, generate a new token on the server and then update the authentication information by leaving and rejoining the channel:

  • 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

The 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 value of 0 indicates that you have successfully joined the channel. Otherwise, an error code is returned. For more information, see Error code list. Common error codes include the following:

  • ERR_JOIN_BAD_APPID: The AppId does not exist.

  • ERR_JOIN_INVALID_APPID: The AppId is invalid.

  • ERR_JOIN_BAD_CHANNEL: The channel does not exist.

  • ERR_JOIN_INVALID_CHANNEL: The channel is invalid.

  • ERR_JOIN_BAD_TOKEN: The token does not exist.

  • ERR_JOIN_TIMEOUT: The request to join the channel timed out.

  • ERR_JOIN_BAD_PARAM: The parameters for joining the channel are incorrect.

  • ERR_JOIN_FAILED: Failed to join the channel.

  • ERR_JOIN_CONFIG_INVALID: The parameters for joining the channel are invalid, such as an empty token.

channel

String

The channel ID.

userId

String

The user ID.

elapsed

int

The time elapsed to join the channel, in milliseconds.

onLeaveChannelResult

Reports the result of leaving a channel.

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

Triggering conditions

When an 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 for the current channel session.

Note

If <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#fef395c4beqdt" id="fdccda828dzqt">leaveChannel</a> is immediately followed by a call to destroy to destroy the engine, this callback will not be triggered.

Parameters

Parameter

Type

Description

result

int

The result of leaving the channel. A value of 0 indicates success. Other values are error codes.

stats

AliRtcStats

A summary of data statistics for the session.

onRemoteUserOffLineNotify

A 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 any reason.

Triggers

  • 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), this callback is triggered.

  • No data is received from a remote streamer for an extended period, and the streamer is considered offline.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

reason

AliRtcUserOfflineReason

The reason why the user went offline.

onRemoteUserOnLineNotify

Callback for when a remote user goes online.

public void onRemoteUserOnLineNotify(String uid, int elapsed);

This callback notifies the local client that a remote user has joined the channel.

Triggers

  • A remote user successfully joins the channel.

  • After the local user joins a channel, this callback is triggered for each user who is already in the channel. This helps you identify users who have already joined.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

elapsed

int

The time elapsed, in milliseconds, from when the local user starts to join the channel until this callback is triggered.

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 the stream ingest status of a remote user changes, informing you in real time whether the remote user is pushing audio and video streams so you can show or hide the user's audio and video information on the interface.

Note

This callback returns the stream ingest status of the remote user. To identify which stream has become unavailable, you must compare the status before and after this callback is triggered.

Trigger conditions

This callback is triggered in the following scenarios:

  • A remote user starts ingesting an audio or video stream.

  • A remote user stops ingesting all audio and video streams.

  • This callback is triggered in interactive mode when a remote user calls setClientRole to switch from a viewer to a streamer and starts stream ingest.

For example, if a remote user disables stream ingest for video, this callback is not triggered:

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

  • The remote user then pushes a screen sharing stream. The stream ingest status changes from only the camera stream to both the camera and screen sharing streams. The callback returns AliRtcVideoTrackBoth to indicate that both streams are active.

  • The remote user stops pushing the camera stream but keeps only the screen sharing stream. The stream ingest status changes from pushing both the camera and screen sharing streams to pushing only the screen sharing stream. The callback returns AliRtcVideoTrackScreen to indicate that only the screen sharing stream is available.

  • The remote user then stops pushing the screen sharing stream. The stream ingest status changes from only the screen sharing stream to no video stream. The callback returns AliRtcVideoTrackNo to indicate that no video stream is active.

Parameter descriptions

Parameter

Type

Description

uid

String

The ID of the remote user.

audioTrack

AliRtcAudioTrack

The audio stream of the remote user after the change.

videoTrack

AliRtcVideoTrack

The video stream of the remote user after the change.

onBye

Triggered when a user is removed from a channel by the server or when the channel is shut down.

public void onBye(int code);

This callback is triggered when a user is disconnected for any reason or when a session ends. You can check the callback parameter code to determine the reason for the disconnection and handle it accordingly.

Triggers

  • The user is removed from the channel by the server.

  • The session ends because the server shuts down the channel.

  • The user is involuntarily disconnected. The client must then try to resume the session or reconnect.

Parameters

Parameter

Type

Description

code

int

The type of the onBye event. For more information, see AliRtcOnByeType.

onAudioPublishStateChanged

Callback for changes in the audio stream ingest status.

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

The SDK triggers this callback when the ingest status of the local user's audio stream changes.

When triggered

The ingest status changes in scenarios such as the following:

  • The stream ingest stops.

  • 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 a viewer.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

The previous ingest status.

newState

AliRtcPublishState

The current ingest status.

elapseSinceLastState

int

The time elapsed since the last state change, in milliseconds.

channel

String

The current channel ID.

onAudioSubscribeStateChanged

Callback for a change in the audio stream subscription status.

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

This callback notifies the local user when the subscription status of a remote user's audio stream changes. It provides the new status and the time elapsed since the last status change.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

oldState

AliRtcSubscribeState

The previous subscription status.

newState

AliRtcSubscribeState

The current subscription status.

elapseSinceLastState

int

The time elapsed since the last status change, in milliseconds.

channel

String

The current channel ID.

onUserAudioMuted

Occurs when a remote user stops sending audio data.

public void onUserAudioMuted(String uid ,boolean isMute);

Parameters

Parameter

Type

Description

uid

String

The user who mutes the audio.

isMute

boolean

The new mute state of the user's audio. The valid values are:

  • true: Muted.

  • false: Unmuted.

onUserAudioInterruptedBegin

Occurs when a user's audio is interrupted.

public void onUserAudioInterruptedBegin(String uid);

Parameters

Parameter

Type

Description

uid

String

The user whose audio is interrupted.

onUserAudioInterruptedEnded

Occurs when a user's audio interruption ends.

public void onUserAudioInterruptedEnded(String uid);

Parameters

Parameter

Type

Description

uid

String

The ID of the user whose audio was interrupted.

onVideoPublishStateChanged

Callback for video stream ingest status changes.

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

This callback is triggered when the status of the local user's video stream ingest changes.

Parameters

Parameter

Type

Description

oldState

AliRtcPublishState

The previous stream ingest status.

newState

AliRtcPublishState

The current stream ingest status.

elapseSinceLastState

int

The time elapsed since the last status change, in milliseconds.

channel

String

The current channel ID.

onVideoSubscribeStateChanged

Callback for changes in the camera stream subscription status.

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

This callback notifies the local user about changes in the subscription status of a remote user's camera stream. The callback provides the new subscription status and the time elapsed since the previous status.

Related callbacks

A video stream includes a camera stream and a screen sharing stream. This callback is for changes in the camera stream subscription status. For screen sharing streams, the related callback is onScreenShareSubscribeStateChanged.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

oldState

AliRtcSubscribeState

The previous subscription status.

newState

AliRtcSubscribeState

The current subscription status.

elapseSinceLastState

int

The time elapsed since the last status change.

channel

String

The current channel ID.

onUserVideoMuted

Occurs when a remote user sends black video frames.

public void onUserVideoMuted(String uid, boolean isMute);

Parameters

Parameter

Type

Description

uid

String

The user who calls enableLocalVideo.

isMute

boolean

Indicates whether to send black frames. Valid values:

  • true: Sends black frames.

  • false: Sends a normal video stream.

onUserVideoEnabled

Occurs when a remote user enables or disables their camera stream.

public void onUserVideoEnabled(String uid, boolean isMute);

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

isMute

boolean

Indicates whether the camera stream is enabled. The valid values are:

  • true: The camera stream is enabled.

  • false: The camera stream is disabled.

onUserWillResignActive

A remote user's application moves to the background.

public void onUserWillResignActive(String uid);

Parameters

Parameter

Type

Description

uid

String

The user ID.

onUserWillBecomeActive

A remote user's application returns to the foreground.

public void onUserWillBecomeActive(String uid);

Parameters

Parameter

Type

Description

uid

String

The user ID.

onAliRtcStats

The callback for the statistics of the current session. The software development kit (SDK) triggers this callback every two seconds.

public void onAliRtcStats(AliRtcEngine.AliRtcStats stats);

Parameters

Parameter

Type

Description

stats

AliRtcStats

Session statistics.

onAudioEffectFinished

This callback is triggered when the playback of a local sound effect finishes.

void OnAudioEffectFinished(int soundId);

Parameters

Parameter

Type

Description

soundId

int

The ID assigned to the sound effect file.

onAudioFileInfo

The callback for audio file information.

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

This callback is triggered by a call to getAudioFileInfo to retrieve audio file information. The callback provides information, such as the duration of the audio file, or an error message.

Parameters

Parameter

Type

Description

info

AliRtcEngine.AliRtcAudioFileInfo

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

errorCode

AliRtcEngine.AliRtcAudioAccompanyErrorCode

The error code for audio accompaniment. This code indicates errors such as a failure to open or decode the file.

onMediaExtensionMsgReceived

This callback is triggered when a media extension message is received.

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

After a client calls sendMediaExtensionMsg to send a message, other clients receive the data through this callback.

Parameters

Parameter

Type

Description

uid

String

The ID of the user who sent the media message.

payloadType

int

The payload type. The value is 5 if the message is sent by sendMediaExtensionMsg. If the message is sent by sendMediaExtensionMsgEx, the value is the specific type.

message

byte[]

The media extension message.

onFirstRemoteVideoFrameDrawn

This callback is triggered when the first video frame from a remote user is displayed.

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

This callback notifies the application that the first video frame from a remote user has been successfully received and rendered. Use this callback to 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

The ID of the remote user.

videoTrack

AliRtcVideoTrack

The type of the received video stream.

width

int

The width of the video stream.

height

int

The height of the video stream.

elapsed

int

The time elapsed, in milliseconds, from when the local user joins the channel until the first frame of the video stream is displayed.

onFirstLocalVideoFrameDrawn

This callback is triggered when the first frame of the local video is drawn.

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

This callback notifies the app when the first local video frame is drawn after the local user enables the camera. Use this callback to monitor the setup speed of the local video preview, evaluate device performance, and optimize the user experience, such as by displaying a "Camera is ready" message or adjusting the preview layout.

Parameters

Parameter

Type

Description

width

int

The width of the local preview video.

height

int

The height of the local preview video.

elapsed

int

The time elapsed, in milliseconds, from when the local user joins the channel until the first frame is displayed in the local preview.

onFirstVideoFrameReceived

A callback triggered when the first video frame from a remote user is received.

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

This callback is triggered when the local user receives the first video frame from a remote user. This lets you monitor the video link setup time, assess network quality, and optimize the user experience. For example, you can display a "Video is ready" message or adjust playback logic.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

videoTrack

AliRtcVideoTrack

The type of the received video stream.

timeCost

int

The time, in milliseconds (ms), from when the user joins the channel to when the first video packet is sent.

onFirstVideoPacketSent

Notifies the application that the first video packet has been sent.

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

This callback is triggered when the local user successfully sends the first video data packet. It helps developers monitor video link establishment speed, evaluate local device performance, and optimize the user experience. For example, you can display a "Video sent" message or adjust the collection policy.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

videoTrack

AliRtcVideoTrack

The type of the video stream.

timeCost

int

The time elapsed from joining the channel to sending the first video packet. Unit: milliseconds.

onFirstAudioPacketSent

Callback for when the first audio packet is sent.

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

This callback is triggered when the local user successfully sends the first audio data packet. Use this callback to monitor the establishment speed of the audio sending link, evaluate local device and system performance, and optimize the user experience.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

track

AliRtcAudioTrack

The audio track type.

timeCost

int

The time elapsed from joining the channel to sending the first audio packet, in milliseconds (ms).

onFirstVideoPacketReceived

Callback for the first received video packet.

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

This callback is triggered when the first video packet from a remote user is received. Use this callback to monitor the speed at which the video link is established or to update UI components for the playback stream.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

videoTrack

AliRtcVideoTrack

The type of the received video stream.

timeCost

int

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

onFirstAudioPacketReceived

Callback for receiving the first audio packet.

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

This callback is triggered when the local user receives the first audio packet from a remote user. Use this callback to monitor the audio link setup speed, evaluate network quality, and optimize the user experience, such as displaying an "Audio connected" prompt or adjusting the playback policy.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

track

AliRtcAudioTrack

The type of the received audio stream.

timeCost

int

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

onFirstRemoteAudioDecoded

Callback for the first decoded frame of a remote audio stream.

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

This callback occurs when the first frame of a remote audio stream is pulled and decoded. It signals that the remote user's audio stream is decoded and ready for playback. Use this callback to measure the time-to-first-frame latency or update the UI component for the playback stream.

Parameters

Parameter

Type

Description

uid

String

The remote user ID.

track

AliRtcAudioTrack

The type of the received audio stream.

elapsed

int

The time elapsed (in milliseconds) from when the local user joins the channel to the decoding of the first audio frame.

onAudioAccompanyStateChanged

Callback for the playback status of the local audio accompaniment.

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

This callback is triggered when the playback status of the local audio accompaniment changes. It reports the current status in real time, such as started, paused, or finished, and any potential error codes. Use this callback to monitor playback progress, handle exceptions, and update the user interface.

Parameters

Parameter

Type

Description

playState

AliRtcEngine.AliRtcAudioAccompanyStateCode

The playback status of the audio accompaniment.

errorCode

AliRtcEngine.AliRtcAudioAccompanyErrorCode

The playback error code. This error occurs mainly when opening or decoding the file.

onRemoteAudioAccompanyStarted

A callback that is triggered when a remote user starts playing an audio accompaniment.

public void onRemoteAudioAccompanyStarted(String uid);

This callback notifies the local application when a remote user starts playing an audio accompaniment, such as background music. Use this callback to run initialization logic, such as updating the UI, adjusting the volume, or notifying other users.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user who started the audio accompaniment.

onRemoteAudioAccompanyFinished

Callback for when the audio accompaniment of a remote user finishes playback.

public void onRemoteAudioAccompanyFinished(String uid);

This callback notifies the local application when the audio accompaniment of a remote user finishes playback. Audio accompaniment includes items such as background music and sound effects. Use this callback to execute subsequent logic, such as displaying a prompt or updating a status.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user whose audio accompaniment finished playback.

onVideoResolutionChanged

The resolution of a remote video stream changes.

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

This callback is triggered when the resolution of a remote user's video stream changes. This can happen when a user switches cameras, adjusts the video definition, or when the resolution decreases due to network fluctuations. Use this callback to dynamically adjust local video rendering logic, such as UI layout, canvas scaling, and performance optimization.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user whose video resolution changed.

videoTrack

AliRtcVideoTrack

The type of the video stream, such as a camera stream or a screen stream.

width

int

The new video resolution width.

height

int

The new video resolution height.

onRtcLocalVideoStats

Reports data statistics for the published local video stream.

public void onRtcLocalVideoStats(AliRtcEngine.AliRtcLocalVideoStats aliRtcStats);

This callback reports real-time statistics for the local video stream. It provides information about the encoding and transport status, such as bitrate and frame rate. Use this callback to monitor video quality, diagnose performance issues, or dynamically adjust encoding parameters.

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcLocalVideoStats

The statistics for the published local video stream. This includes the publishing bitrate and frame rate. For more information, see AliRtcLocalVideoStats.

onRtcRemoteVideoStats

Statistics for a subscribed remote video stream.

public void onRtcRemoteVideoStats(AliRtcEngine.AliRtcRemoteVideoStats aliRtcStats);

This callback reports real-time statistics for a remote video stream, such as its encoding and transport status. The statistics include bitrate, frame rate, resolution, latency, and stuttering. 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 remote video stream. This includes information such as the remote user ID, video resolution, frame rate, and stutter count. For more information, see AliRtcRemoteVideoStats.

onRtcRemoteAudioStats

Reports statistics for a subscribed remote audio stream.

public void onRtcRemoteAudioStats(AliRtcEngine.AliRtcRemoteAudioStats aliRtcStats);

This callback reports real-time statistics about the audio quality of a remote user, such as audio quality, packet loss rate, and latency. Use this callback to monitor the stability of the remote audio link, diagnose network issues, and dynamically adjust the playback policy, such as enabling noise reduction or prompting the user to optimize their network.

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcRemoteAudioStats

Statistics for the remote audio stream. This includes the remote user ID, audio quality, packet loss rate, number of stutters, and latency. For more information, see AliRtcRemoteAudioStats.

onRtcLocalAudioStats

Reports statistics for the local audio stream.

public void onRtcLocalAudioStats(AliRtcEngine.AliRtcLocalAudioStats aliRtcStats);

This callback reports statistics for the published local audio stream. It provides real-time information about the encoding and transport status, such as bitrate, sample rate, the number of sound channels, and packet loss rate. You can use this callback to monitor the stability of the local audio link, diagnose performance issues, and dynamically adjust the encoding policy, such as reducing the bitrate.

Parameters

Parameter

Type

Description

aliRtcStats

AliRtcEngine.AliRtcLocalAudioStats

Statistics for the published local audio stream. This includes the audio stream type, send bitrate, send sample rate, and the number of sound channels. For more information, see AliRtcLocalAudioStats.

onAudioFocusChange

A callback for audio focus changes. This is for the Android platform only.

public void onAudioFocusChange(int focusChange);

This callback provides a notification about the result of an audio focus change. The SDK automatically requests audio focus by default. If an external application needs to use the audio focus, it must request the focus again after it receives this callback from the SDK.

When triggered

This callback is triggered when the status of the audio output device changes, such as inserting or unplugging headphones, switching to a Bluetooth device, or switching between the earpiece and the speaker.

Parameters

Parameter

Type

Description

focusChange

int

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

onAudioRouteChanged

This callback is triggered when the audio route changes. It is available only on Android and iOS.

public void onAudioRouteChanged(AliRtcEngine.AliRtcAudioRouteType routing);

This callback notifies the application of a change in the audio output path, such as when a user plugs in headphones or switches to the speaker. Use this callback to dynamically adjust the audio output policy, such as switching the microphone mode or adjusting the volume.

Parameters

Parameter

Type

Description

routing

AliRtcEngine.AliRtcAudioRouteType

The current audio route.

onRemoteUserSubscribedDataChannel

A callback that indicates the data channel is ready to send messages.

public void onRemoteUserSubscribedDataChannel(String uid);

This callback is triggered when a remote user subscribes to the Data Channel. It notifies you that the specified remote user is ready to receive custom messages. You can then safely call sendDataChannelMsg to send data to the user. This callback is a key mechanism for reliable message delivery. It prevents packet loss or failures that occur when you send messages before the target user subscribes to the Data Channel.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

onDataChannelMessage

Callback for receiving custom messages from the data channel.

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

The Alibaba Real-Time Communication (ARTC) software development kit (SDK) lets you send and receive custom messages. You can send custom real-time messages while you transmit audio and video data. This callback is triggered when a custom message is received from the data channel. For more information, see Send and receive custom messages.

Note
  • In an interactive scenario, a streamer can send and receive messages. A viewer can only receive messages.

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

When triggered

This callback is triggered on the receiver's side after a sender calls sendDataChannelMsg to send a custom message. The receiver must have the data channel feature enabled.

Parameters

Parameter

Type

Description

uid

String

The user ID of the sender.

msg

AliRtcEngine.AliRtcDataChannelMsg

The custom message that is received.

onAudioVolume

Reports the 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> method. Once enabled, the SDK triggers this callback 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 where users are ingesting streams. The callback result contains volume information for local and remote speakers.

Parameters

Parameter

Type

Description

speakers

List<AliRtcEngine.AliRtcAudioVolume>

An array that contains the volume information of users, including the user UID, voice status, and volume.

  • A UID of 0 indicates the local speaker.

  • A UID of 1 indicates the mixed volume of all remote users.

  • Other values indicate the volume information of a specific remote user identified by the UID.

totalVolume

int

The total volume after audio mixing. The value ranges from 0 to 255.

For the local user, this parameter is the volume after audio mixing. For remote users, this parameter is the total mixed volume of all speakers.

onActiveSpeaker

The callback that is invoked when a user speaks.

public void onActiveSpeaker(String uid);

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

Trigger conditions

The SDK triggers this callback to report the uid of the most active remote user when there are two or more users in the channel and a remote active user is detected.

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

  • If the most active remote speaker changes, the SDK triggers this callback again to report the UID of the new most active remote speaker.

Parameters

Parameter

Type

Description

uid

String

The user ID (UID) of the speaker. A UID of "0" indicates the local speaker. This parameter returns the UID of the loudest speaker over the current time segment, not the UID of the speaker with the loudest instantaneous volume.

OnTestAudioVolume

Callback for volume information during pre-call testing.

public void OnTestAudioVolume(int volume);

This callback is triggered when you call startAudioCaptureTest to run a pre-call audio device test. It reports the volume of the audio capture device. Use this information to verify that the local audio capture device is working correctly.

Parameters

Parameter

Type

Description

volume

int

The volume value.

onCapturedAudioFrame

Callback for captured raw audio data.

boolean onCapturedAudioFrame(AliRtcAudioFrame frame);

This callback provides the raw audio data captured by the current device. This callback is disabled by default. To get this audio data:

  • Enable this callback function using the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). Use the config parameter to set the sample rate, the number of sound channels, and the read/write mode.

  • Call registerAudioFrameObserver to register an object to accept the audio data.

Note

This callback lets you set the sample rate, the number of sound channels, and the read/write mode.

Limitations

Do not perform any time-consuming operations in this callback function. Otherwise, audio issues 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 returns audio data after 3A processing. The callback is disabled by default. To get this audio data:

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

  • Call registerAudioFrameObserver to register the object that accepts audio data.

Note

This API lets you set the sample rate, the number of sound channels, and the read/write mode.

Call limits

Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The audio data.

Return value

  • true: The operation is successful.

  • false: The operation failed.

onPublishAudioFrame

Callback for stream ingest audio data.

boolean onPublishAudioFrame(AliRtcAudioFrame frame);

Use this callback to get the audio data for stream ingest. This feature is disabled by default. To get the audio data:

  • Enable this callback by setting the audioSource parameter in enableAudioFrameObserver(true,audioSource,config). The config parameter also lets you set the sample rate, the number of sound channels, and the read/write mode.

  • Call registerAudioFrameObserver to register the object that receives audio data.

Note

This API supports setting the sample rate and the number of sound channels, but only in read-only mode.

Call limits

Do not perform time-consuming operations in this callback function. Otherwise, audio issues may occur.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

Audio data.

Return value

  • true: The operation succeeded.

  • false: The operation failed.

onPlaybackAudioFrame

Callback for playback audio data.

boolean onPlaybackAudioFrame(AliRtcAudioFrame frame);

Use this callback to get playback audio data. This callback is disabled by default. To get the audio data:

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

  • Call registerAudioFrameObserver to register the object that receives audio data.

Note

This API lets you set the sample rate, the number of sound channels, and the read/write pattern.

Call limits

Do not perform any time-consuming operations in this callback function because this may cause abnormal audio.

Parameters

Parameter

Type

Description

frame

AliRtcAudioFrame

The audio data.

Return values

  • true: The call succeeded.

  • false: The call failed.

onRemoteUserAudioFrame

Callback for remote audio stream data

boolean onRemoteUserAudioFrame(String uid, AliRtcAudioFrame frame);

Use this callback to get the remote audio data from a specified user. This callback is disabled by default. To get the audio data:

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

  • Call registerAudioFrameObserver to register an object to receive the audio data.

Note

This API lets you set the read/write mode, but not the sample rate or the number of sound channels.

Limitations

Do not perform time-consuming operations in this callback function. Doing so may cause audio issues.

Parameters

Parameter

Type

Description

uid

String

The user ID.

frame

AliRtcAudioFrame

The audio data.

Returns

  • true: The operation was successful.

  • false: The operation failed.

OnDestroyCompletion

A callback for the completion of DPI engine destruction.

void OnDestroyCompletion();

This callback confirms that the SDK DPI engine instance is destroyed, so you can create a new instance.

When triggered

This callback is triggered after you call destroy[2/2] and the DPI engine destruction is complete.

onTextureCreate

A callback for when the OpenGL context is created.

void onTextureCreate(long context);
Note

This callback is triggered when the SDK creates its internal OpenGL context.

When triggered

This callback is triggered when the SDK creates its internal OpenGL context. Use this callback to initialize related resources.

Parameters

Parameter

Type

Description

context

long

The OpenGL context.

onTextureUpdate

An OpenGL texture update callback.

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

Trigger conditions

This callback triggers after each video frame is uploaded to an OpenGL texture. If an external observer for OpenGL texture data is registered, use this callback to process the texture and return the processed texture ID.

Parameters

Parameter

Type

Description

textureId

int

The OpenGL context.

width

int

The video width.

height

int

The video height.

videoSample

AliRtcVideoSample

The video frame data.

Return value

Returns the new texture ID or the original texture ID. If the return value is <0, the texture ID is not updated.

onTextureDestroy

void onTextureDestroy();

Trigger condition

This callback is triggered when the internal OpenGL context of the SDK is destroyed. Implement this callback to release relevant resources.

onLocalVideoSample

A callback for captured local video data.

public boolean onLocalVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoSample);

This callback provides the raw video frames, such as YUV data, captured from the local camera. You can use this callback to apply custom video processing, such as adding filters, watermarks, or transcoding. After processing, you can decide whether to send the data back to the software development kit (SDK) for 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 the video data observer, the SDK captures the corresponding video frame.

Parameters

Parameter

Type

Description

sourceType

AliRtcVideoSourceType

The video source type.

videoSample

AliRtcVideoSample

The video data.

Return value

  • true: The data is written back to the SDK. This is the default. You must return true if you modify the AliRtcVideoSample.data object.

  • false: The data is not written back to the SDK. Return false if you directly modify the AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV objects.

onPreEncodeVideoSample

A callback for subscribed local video data before encoding.

public boolean onPreEncodeVideoSample(AliRtcVideoSourceType sourceType, AliRtcVideoSample videoRawData);

This callback provides the raw data of a local video frame, such as data in YUV format, before the SDK encodes the frame. Use this callback to implement custom logic, such as adding a watermark, adjusting colors, or transcoding the video. After processing, decide whether to return the modified data to the SDK for encoding.

Parameters

Parameter

Type

Description

sourceType

AliRtcVideoSourceType

Video stream type

videoRawData

AliRtcVideoSample

Raw video data

Return values

  • true: The data is written back to the SDK. This is the default. This value is required when AliRtcVideoSample.data is modified.

  • false: The data is not written back to the SDK. Use this value when you directly modify AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, and AliRtcVideoSample.dataFrameV.

onRemoteVideoSample

The callback for subscribed remote video data.

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

This callback is triggered when data from a subscribed remote video stream is available. It provides the raw video frame data, such as data in YUV format, from the remote user. Use this callback to implement custom logic, such as adding filters, watermarks, or transcoding. You can then decide whether to return the processed data to the SDK for rendering.

Parameters

Parameter

Type

Description

callId

String

The user ID.

sourceType

AliRtcVideoSourceType

The video stream type.

videoSample

AliRtcVideoSample

The raw video data.

Return value

  • true: The data is written back to the SDK. This is the default behavior. The data must be written back if AliRtcVideoSample.data is modified.

  • false: The data is not written back to the SDK. Use this value if you directly modify AliRtcVideoSample.dataFrameY, AliRtcVideoSample.dataFrameU, or AliRtcVideoSample.dataFrameV.

onGetVideoFormatPreference

Specifies the output format for video data.

public AliRtcVideoFormat onGetVideoFormatPreference();

Return value

The desired video output format.

onGetObservedFramePosition

Video outputs.

public int onGetObservedFramePosition();

Use this callback to specify the processing stage of the video frames that the software development kit (SDK) outputs, such as after capture, before encoding, and after stream pulling.

Return value

An enumeration value of the AliRtcVideoObserPosition type. This value specifies the expected video output content, such as captured data, pulled stream data, or data before encoding.

onPublishLiveStreamStateChanged

A callback that is triggered when the status of the bypass live stream changes.

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

Parameters

Parameter

Type

Description

streamUrl

String

The ingest URL.

state

AliRtcLiveTranscodingState

The status of the bypass live stream.

errorCode

AliEngineLiveTranscodingErrorCode

The error code.

onPublishTaskStateChanged

The callback for bypass task status changes.

public void onPublishTaskStateChanged(String streamUrl, AliRtcTrascodingPublishTaskStatus state);

Parameters

Parameter

Type

Description

streamUrl

String

The ingest URL.

state

AliRtcTrascodingPublishTaskStatus

The status of the bypass stream ingest task.

onNetworkQualityChanged

A callback that is triggered when the network quality changes.

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

Parameters

Parameter

Type

Description

uid

String

The user ID. If this parameter is empty, the callback reports the uplink and downlink network status of the local user.

upQuality

AliRtcNetworkQuality

The uplink network status.

downQuality

AliRtcNetworkQuality

The downlink network status.

onNetworkQualityProbeTest

This callback for network quality probing is triggered about 3 seconds after the probe starts.

public void onNetworkQualityProbeTest(AliRtcNetworkQuality quality){}

Parameters

Parameter

Type

Description

quality

AliRtcNetworkQuality

The network quality.

onNetworkQualityProbeTestResult

The callback for the network quality probe result. This callback is triggered after the probe runs for about 30 seconds.

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

Parameters

Parameter

Type

Description

code

int

The return value. A value of 0 indicates that the probe is successful. A value of -1 indicates that the probe failed because the connection was lost due to poor network conditions.

result

AlirtcNetworkQualityProbeResult

The network quality.

onSnapshotComplete

A callback for snapshot results.

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

This callback provides the result and details of a snapshot.

Parameters

Parameter

Type

Description

userId

String

The user ID.

trackType

AliRtcVideoTrack

The type of the video stream for the snapshot.

bitmap

Bitmap

The snapshot data.

success

boolean

Indicates whether the snapshot was successful.

onScreenSharePublishStateChanged

Callback for changes in the screen sharing stream ingest state.

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

This callback is triggered when the state of the screen sharing stream ingest changes.

Parameters

Parameter

Type

Description

oldState

AliRtcEngine.AliRtcPublishState

The previous stream ingest state.

newState

AliRtcEngine.AliRtcPublishState

The new stream ingest state.

elapseSinceLastState

int

The time elapsed since the last state change, in milliseconds.

channel

String

The name of the current channel.

onScreenShareSubscribeStateChanged

A callback for changes in the subscription status of a screen sharing stream.

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

This callback is triggered when the subscription status of the local user to a remote user's screen sharing stream changes.

Parameters

Parameter

Type

Description

uid

String

The ID of the remote user.

oldState

AliRtcEngine.AliRtcSubscribeState

The previous subscription status.

newState

AliRtcEngine.AliRtcSubscribeState

The current subscription status.

elapseSinceLastState

int

The time elapsed since the last state change, in milliseconds.

channel

String

The current channel.

onOccurError

Error notification.

public void onOccurError(int error, String message);

This global callback notifies the application layer when a critical error occurs in the internal engine of the Alibaba Real-Time Communication (ARTC) software development kit (SDK). Use this callback to get the error code and message for exception handling, log recording, or user prompts.

Parameters

Parameter

Type

Description

error

int

The error type. For more information, see the list of error codes.

message

String

The error message.

OnLocalAudioStateChanged

Callback for the status of the local audio device.

public void OnLocalAudioStateChanged(int state);

This callback is triggered when the status of the local audio capture device changes. For example, this happens when startAudioCapture is called to start audio capture or stopAudioCapture is called to stop audio capture.

Parameters

Parameter

Type

Description

state

int

  • 0: Not created

  • 1: Capturing

  • 2: Shutting down

  • 3: Shut down

setParameter

Sets a custom parameter.

public abstract int setParameter(String param);

Parameters

Parameter

Type

Description

param

String

The custom parameter.

getParameter

Gets a custom parameter.

public abstract String getParameter(String param);

Parameter descriptions

Parameter

Type

Description

param

String

A custom parameter.

registerAudioVolumeObserver

Registers an audio volume observer.

public abstract void registerAudioVolumeObserver(AliRtcAudioVolumeObserver observer);

This method registers an audio volume observer. To cancel the registration, call unRegisterAudioVolumeObserver.

When to call

  • When you need to obtain volume information, you need to 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 also call this method to register an object to receive the relevant data.

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

The object that receives volume data.

unRegisterAudioVolumeObserver

Unregisters the audio volume observer.

public abstract void unRegisterAudioVolumeObserver();

This method is the counterpart to registerAudioVolumeObserver and unregisters the output object for audio volume data.

When to call

After registering an audio volume observer by calling registerAudioVolumeObserver, call this method to unregister the observer.

enableAudioFrameObserver

Sets the audio callback parameters.

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

Call this method to enable or disable the callback for a specific type of audio data. The callback lets you obtain various types of raw and encoded audio data. By default, the callback is disabled.

Note

When you call this method to enable the audio data callback for an AliRtcAudioSource, you must also call the registerAudioFrameObserver method to register the object that receives the audio data.

When to call

Call this method when you need to obtain audio data.

Parameters

Parameter

Type

Description

enable

boolean

Specifies whether to enable the audio data callback.

audioSource

AliRtcAudioSource

The type of data source for the callback. The options include captured audio data (0), post-3A processed audio data (1), ingested stream audio data (2), playback audio data (3), mixed audio data from stream ingest and playback (4), and pulled stream audio data (5).

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

  • You cannot modify audio parameters, such as the sample rate and the number of sound channels, for pulled stream audio data.

config

AliRtcAudioFrameObserverConfig

The audio callback parameter settings, such as the sample rate, the number of sound channels, and the read/write mode (read-only, write-only, or read/write). If this parameter is null, the default settings are used: a sample rate of 48000, 1 sound channel, and the ReadOnly mode.

Returns

  • 0: The method call is successful.

  • <0: The method call failed.

registerAudioFrameObserver

Registers an audio data callback.

public abstract void registerAudioFrameObserver(AliRtcAudioFrameObserver observer);

This method registers an object to receive audio data callbacks.

When to call

To receive audio data from callbacks such as onCapturedAudioFrame, onProcessCapturedAudioFrame, onPublishAudioFrame, onPlaybackAudioFrame, and onRemoteUserAudioFrame, call this method to register an object. To cancel the registration, call this method again and pass null.

Restrictions

Call enableAudioFrameObserver to enable callbacks for a specific AliRtcAudioSource. Otherwise, the specified observer cannot receive data.

Parameters

Parameter

Type

Description

observer

AliRtcAudioFrameObserver

The object instance that receives audio data callbacks. Pass null to cancel the registration.

registerVideoSampleObserver

Registers a video data output object.

public abstract void registerVideoSampleObserver(AliVideoObserver observer);

Call this method to register a video data output object. To unregister the object, call the unRegisterVideoSampleObserver method.

When to call

To obtain raw video data, such as data in YUV or RGBA format, call this method to register a video data observer. This lets you obtain video data from different stages. AliRtcVideoObserver is the video data observer class.

Related callbacks

After you register the video data output observer, the software development kit (SDK) triggers the callbacks that you implement in the AliRtcVideoObserver interface for each captured video frame. Implement the following callbacks as needed:

Parameters

Parameter

Type

Description

observer

AliRtcVideoObserver

The video data output object.

Returns

The output data is returned through the AliVideoObserver callbacks.

unRegisterVideoSampleObserver

Unregisters the video sample observer.

public abstract void unRegisterVideoSampleObserver();

This method is the counterpart to <a baseurl="t2309760_v6_0_0.xdita" data-node="4086566" data-root="16090" data-tag="xref" href="#927fcde6fenlk" id="dcf635790da7v">registerVideoSampleObserver</a> and unregisters the object that is used to export video data.

registerLocalVideoTextureObserver

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

public abstract void registerLocalVideoTextureObserver(AliTextureObserver observer);

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

Note

This method is valid only for the local camera video stream.

Related callbacks

After you register the observer for OpenGL texture data of the local camera stream, the software development kit (SDK) triggers the callbacks that you implemented in the AliRtcTextureObserver interface for each captured video frame. Implement the following callbacks as needed:

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

  • onTextureUpdate: This callback is triggered each time a video frame is uploaded to the OpenGL texture. If an external observer for OpenGL texture data is registered, process the texture in this callback and return the processed texture ID. Note: The return value must be a valid texture ID. If no processing is done, return the textureId parameter.

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

Parameters

Parameter

Type

Description

observer

AliRtcTextureObserver

The observer for OpenGL texture data.

Returns

The output data is returned through the AliVideoObserver callback.

unRegisterLocalVideoTextureObserver

Unregisters the observer of the local camera's OpenGL texture data stream.

public abstract void unRegisterLocalVideoTextureObserver();

This method is the counterpart to registerLocalVideoTextureObserver and is used to unregister.

snapshotVideo

Takes a snapshot of a video stream.

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

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

Limitations

This method is an asynchronous operation. A return value of 0 indicates that the method call is successful, but the software development kit (SDK) has not yet captured the snapshot.

Callbacks

After a successful method call, the SDK triggers the onSnapshotComplete callback. This callback indicates whether the snapshot was captured and provides the snapshot details.

Parameters

Parameter

Type

Description

userId

String

The user ID. If userId is null or an empty string (""), a snapshot of the local user is captured.

trackType

AliRtcVideoTrack

The type of video stream to capture. Only the following values are supported:

  • AliRtcVideoTrackCamera: The camera stream.

  • AliRtcVideoTrackScreen: The screen sharing stream.

Returns

  • 0: The method call is successful. The result of the snapshot is returned in the onSnapshotComplete callback.

  • A non-zero value: The method call failed. An error code is returned.

setLogDirPath

Sets the storage path for SDK log files.

public static int setLogDirPath(String logDirPath);

Parameters

Parameter

Type

Description

logDirPath

String

The absolute path to the folder where log files are saved. The default path is the app folder.

Returns

A return value of 0 indicates a successful call. A non-zero value indicates a failed call. Note To prevent log loss, call this method before calling any other SDK methods. 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

The 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 video display.

Limitations

This method is available only on Android and iOS.

Parameters

Parameter

Type

Description

mode

AliRtcOrientationMode

The device orientation.

Returns

None.

requestAudioFocus

Requests the audio focus.

public abstract int requestAudioFocus();

When to call

The SDK requests the audio focus when it starts, so you do not need to call this method in most cases. If you have called abandonAudioFocus, call this method to resume the audio focus.

Limitations

This method is for Android only.

Parameters

None.

Returns

  • 0: The request failed.

  • 1: The request succeeded.

abandonAudioFocus

Releases the audio focus.

public abstract int abandonAudioFocus();

When to call

The SDK calls this method to release the audio focus when the SDK instance is destroyed. Call this method to manually release the audio focus in certain scenarios. After the audio focus is released, some devices may experience silent playback or low volume. To restore the audio, call requestAudioFocus.

Limitations

For Android only.

Returns

  • 0: Failure.

  • 1: Success.

getNetworkTime

Retrieves the current network time.

public abstract long getNetworkTime();

This method retrieves the current network time in milliseconds (ms). The returned time is the current timestamp that is calibrated by the Network Time Protocol (NTP) and adjusted for the time offset.

When to call

Call this method to get a synchronized network time. Use this time as a baseline to calibrate the local time when you synchronize behavior across multiple devices.

Returns

The current network time in milliseconds.

sendDataChannelMsg

Sends a custom message through the data channel.

public abstract int sendDataChannelMsg(AliRtcDataChannelMsg Msg);

The Alibaba Real-Time Communication (ARTC) software development kit (SDK) lets you send and receive custom messages during audio and video transmission. For example, call this method to send real-time control instructions, status synchronization data, or other business messages. 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 method and pass `"{\"data\":{\"enablePubDataChannel\":true" + ",\"enableSubDataChannel\":true}}"`. You can enable this feature either before or after you join a channel.

  • Messages can contain any data, such as text or images.

Related callbacks

  • The onRemoteUserSubscribedDataChannel callback is triggered when a remote user subscribes to the data channel. You can then send data channel messages to that user.

  • After enabling the custom message channel, the sender can call this method to send custom messages. The receiver listens for the onDataChannelMessage callback to receive these messages.

When to call

Call this method after the local client receives the onRemoteUserSubscribedDataChannel callback. This callback is triggered after a remote user calls setParameter to enable enableSubDataChannel for receiving data channel messages.

Limitations

Users in the streamer role can send and receive messages. Users in the viewer role can only receive messages.

Call `setParameter` to enable the custom message channel.

Parameters

Parameter

Type

Description

Msg

AliRtcDataChannelMsg

The message content.

Return values

  • 0: The call is successful.

  • A non-zero value: The call failed and an error code is returned.

startScreenShare

Important

This interface is deprecated. Use the new startScreenShare interface.

Starts sharing the screen and audio stream.

public abstract int startScreenShare(Intent intent);

Parameters

Name

Description

intent

The Activity that starts screen sharing. Pass null if the Activity is not created externally. This is the recommended option.

Return value

  • 0: The call succeeded.

  • Any other value: The call failed.

startScreenShare

Important

This API is deprecated. Use the new API startScreenShare.

Starts screen sharing.

public abstract int startScreenShare();

Return value

  • 0: Success

  • Other values: Failure

startScreenShare

Starts sharing the screen video stream.

public abstract int startScreenShare(Intent intent, AliRtcScreenShareMode screenShareMode);

Parameters

Name

Description

intent

The activity that starts screen sharing. If you do not create this activity, pass null. This is the recommended setting.

screenShareMode

The screen sharing type. For more information, see AliRtcScreenShareMode.

Return value

  • 0: The call succeeded.

  • Other values: The call failed.

stopScreenShare

Stops sharing the screen and the accompanying audio stream.

public abstract int stopScreenShare();

Return value

  • 0: Success

  • Other values: Failure

setAudioShareVolume

Sets the volume of the audio stream for stream ingest.

public abstract int setAudioShareVolume(int volume);

Parameters

Name

Description

volume

The volume.

Valid values: 0 to 100. Default: 50.

Return value

  • 0: Success.

  • Other values: Failure.

isScreenSharePublished

Checks if a screen sharing stream is being published.

public abstract boolean isScreenSharePublished();

Return value

  • true: A screen sharing stream is being published.

  • false: A screen sharing stream is not being published.

setScreenShareEncoderConfiguration

Sets the video encoding properties for the screen sharing stream.

public abstract void setScreenShareEncoderConfiguration(AliRtcScreenShareEncoderConfiguration config);

This method sets the video parameters for the screen sharing stream, such as resolution, frame rate, bitrate, and video orientation.

Note

Each parameter has a valid range. If a value is set outside the valid range, the SDK automatically adjusts it. As a result, the final configuration may differ from the one you set.

When to call

You can call this method before or after joining a session. If you only need to set these properties once per session, call this method before you join.

Parameters

Parameter

Type

Description

config

AliRtcScreenShareEncoderConfiguration

The predefined encoding properties for screen sharing, such as resolution, frame rate, bitrate, and video orientation.