CloudHub Docs
Download Documents

RTC


CloudHubSDK Android

Channel management

initEngine

Initialize the SDK engine.

public static int initEngine(Context context, RtcEngineListener listener,String configs,String appId,boolean enableMultiCamera)

Parameters

ParametersDescription
contextAndroid context
listenerEvent listener of RtcEngineListener interface
configsKeep Parameters
appIdThe App ID provided by CloudHub for app developers. Only apps with the same App ID can enter the same channel for calls or live broadcasts. One App ID can only be used to create one RtcEngine
enableMultiCameraWhether to allow multiple cameras to publish at the same time

Returns

Details

Please call the interface method of the RtcEngine class on the main thread.

When multi-camera publishing is allowed, the device id of the camera must be specified for each stream published, and the stream cannot be switched to other devices after publishing, unless republished; if multi-camera publishing is not allowed, only one video stream can be published, but this The stream can be switched to other devices, and in each API method that contains cameraIdParameters, cameraIdParameters is ignored.

Note

initEngine3

Initialize the SDK engine.

public static int initEngine3(Context context, RtcEngineListener listener,String configs,String appId,boolean enableMultiCamera)

Parameters

ParametersDescription
contextAndroid application context
listenerEvent listener that implements the RtcEngineListener interface
configsReserved Parameters
appIdApp ID provided by CloudHub for app developers. Only apps with the same App ID can enter the same channel for calls or live broadcasts. One App ID can only be used to create one RtcEngine3
enableMultiCameraWhether to allow multiple cameras to be released at the same time

Returns

Details

Please call the interface method of the RtcEngine3 class on the main thread.

When multi-camera publishing is allowed, the device id of the camera must be specified for each stream published, and the stream cannot be switched to other devices after it is published, unless it is republished; if multi-camera publishing is not allowed, only one video stream can be published, but this The stream can be switched to other devices, and in each API method that contains cameraIdParameters, cameraIdParameters is ignored.

Note

setChannelProfile

Sets the channel profile of the CloudHub RtcEngine.

public static int setChannelProfile(int profile)

Parameters

ParametersDescription
profileThe channel profile of the Cloudhub RtcEngine::

* CHANNEL_PROFILE_COMMUNICATION(0), Communication. This profile applies to scenarios such as an audio call or video call, where all users can publish and subscribe to streams.
* CHANNEL_PROFILE_LIVE_BROADCASTING(1), Live interactive steaming. In this profile, uses have roles, namely, host and audience (default). A host can both publish and subscribe to streams, while an audience can only subscribe to streams. This profile applies to scenarios such as a chat room or interactive video streaming.

Returns

Details

After initialization, the SDK uses the CHANNEL_PROFILE_COMMUNICATION channel profile by default. You can call setChannelProfile to set the channel profile. The CloudHub RtcEngine differentiates channel profiles and applies different optimization algorithms accordingly. For example, it prioritizes smoothness and low latency for a video call, and prioritizes video quality for a video live interactive streaming.

Note

setClientRole

Sets the role of the user in interactive live streaming.

public static int setClientRole(int role)

Parameters

ParametersDescription
roleThe role of a user in interactive live streaming:

* CLIENT_ROLE_BROADCASTER(1), Host. A host can both send and receive streams. If you set this user role in the channel, the SDK automatically calls muteLocalAudioStream(false) and muteLocalVideoStream(false)
* CLIENT_ROLE_AUDIENCE(2), Audience. An audience member can only receive streams. If you set this user role in the channel, the SDK automatically calls muteLocalAudioStream(true) and muteLocalVideoStream(true)

Returns

Details

Before joining the channel, the user needs to set the audience (default) or anchor role through this method. After joining the channel, the user can switch user roles through this method. If you call this method to switch user roles after joining a channel, after the call is successful, the local onClientRoleChanged callback will be triggered; the remote will trigger onUserLeft and onUserJoined callbacks.

Note

joinChannel

Allows a user to join a channel.

public static int joinChannel(String channelId, String uid, String token, String properties,boolean autoSubscribeAudio,boolean autoSubscribeVideo)

Parameters

ParametersDescription
channelIdChannel number. Must be a combination of letters and numbers
uidThe unique identifier of the user in the channel. Must be a combination of letters and numbers. If it is empty, the SDK will automatically generate a GUID as the uid and notify it through the onJoinChannelSuccess callback
tokenThe token generated by the developer’s service side. If the safety requirements are not high, you can pass the null
propertiesUser-defined attributes. Will be synchronized to other users in the channel. It must be a json string and can be passed empty
autoSubscribeAudioSubscribe to audio automatically
autoSubscribeVideoSubscribe to video automatically

Returns

Details

Users in the same channel can talk to each other, and multiple users in the same channel can start a group chat. Users with different AppId cannot call each other. You must call the leaveChannel method to exit the current call before joining another channel. A successful method call of joinChannel triggers the following callbacks: The local client: onJoinChannelSuccess. The remote client: onUserJoined, if the user joining the channel is in the COMMUNICATION profile, or is a host in the LIVE_BROADCASTING profile. When the connection between the client and CloudHub server is interrupted due to poor network conditions, the SDK tries reconnecting to the server. When the local client successfully rejoins the channel, the SDK triggers the onRejoinChannelSuccess callback on the local client. Once the user joins the channel (switches to another channel), the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. If you do not want to subscribe to a specified stream or all remote streams, call the mute methods accordingly.

Note

leaveChannel

Allows a user to leave a channel.

public static int leaveChannel()

Returns

Details

After joining a channel, the user must call the leaveChannel method to end the call before joining another channel. This method returns 0 if the user leaves the channel and releases all resources related to the call. This method call is asynchronous, and the user has not exited the channel when the method call returns. Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.

A successful method call of leaveChannel triggers the following callbacks:

The local client: onLeaveChannel. The remote client: onUserOffline, if the user leaving the channel is in the Communication channel, or is a host in the LIVE_BROADCASTING profile

renewToken

Renews the token when the current token expires.

public static int renewToken(String token)

Parameters

ParametersDescription
tokenThe new token.

Returns

Details

The token expires after a period of time once the token schema is enabled when:

The app should retrieve a new token from the server and call this method to renew it. Failure to do so results in the SDK disconnecting from the server.

getConnectionState

Gets the connection state of the SDK

public static int getConnectionState()

Returns

setListener

Replace the event callback listener.

public static int setListener(RtcEngineListener listener)

Parameters

ParametersDescription
listenerThe new event listener object

Returns

Details

Replace the old listener with the new listener.

Note

The listener can be set to null, but it should be noted that if the listener is null, you cannot receive event notifications from the engine.

Audio management

enableAudio

Enables the audio module.

public static int enableAudio(boolean enable)

Parameters

ParametersDescription
enabletrue :Start the audio engine
false:Close the audio engine

Returns

adjustRecordingSignalVolume

Adjusts the volume of the signal captured by the microphone.

int adjustRecordingSignalVolume(int volume)

Parameters

ParameterDescription
volumeThe volume of the signal captured by the microphone. Including the following:
• 0: Mute.
• 400: (Default) Original volume.

Returns

adjustPlaybackSignalVolume

djusts the playback signal volume of all remote users.

int adjustPlaybackSignalVolume(int volume)

Parameters

ParameterDescription
volumeThe volume of the signal captured by the microphone. Including the following:
• 0: Mute.
• 400: (Default) Original volume.

Returns

adjustUserPlaybackSignalVolume

Adjusts the playback signal volume of a specified remote user.

int adjustUserPlaybackSignalVolume(String uid, int volume)

Parameters

ParameterDescription
uidThe ID of the remote user
volumeThe volume of the signal captured by the microphone. Including the following:
• 0: Mute.
• 100: (Default) Original volume.

Returns

enableLocalAudio

Enables/Disables the local audio capture.

public static int enableLocalAudio(boolean enable)

Parameters

ParametersDescription
enable* true:Turn on local voice capture
* false : Stop local voice capture

Returns

Details

The audio function is enabled by default. This method disables/re-enables the local audio function, that is, to stop or restart local audio capture and processing.

This method does not affect receiving the remote audio streams, and enableLocalAudio(false) is applicable to scenarios where the user wants to receive remote audio streams without sending any audio stream to other users in the channel.

Note

This method is different from the muteLocalAudioStream method:

muteLocalAudioStream

Stops or resumes publishing the local audio stream.

public static int muteLocalAudioStream(boolean mute)

Parameters

ParametersDescription
muteSets whether to stop publishing the local audio stream.
* true:Stop publishing the local audio stream.
* false:Resume publishing the local audio stream.

Returns

Details

This method is used to allow/prohibit sending local audio streams to the network. After successfully calling this method, the remote end will trigger the onRemoteAudioStateChanged callback (reason is REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED / REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED.state_reason_video.

Note

This method does not affect the recording state, and does not disable the microphone.

muteRemoteAudioStream

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

public static int muteRemoteAudioStream(String uid, boolean mute)

Parameters

ParametersDescription
uidThe user ID of the specified remote user.
muteSets whether to stop subscribing to the audio stream of a specified user.
true: Stop subscribing to the audio stream of a specified user.
false: (Default) Resume subscribing to the audio stream of a specified user.

Returns

Note

If you have previously called muteAllRemoteAudioStreams(true) to mute all remote audio, please make sure you have called muteAllRemoteAudioStreams before calling this API /#muteallremoteaudiostreams)(false). muteAllRemoteAudioStreams is global control, muteRemoteAudioStream is fine control.

muteAllRemoteAudioStreams

Stops or resumes subscribing to the audio streams of all remote users.

public static int muteAllRemoteAudioStreams(boolean mute)

Parameters

ParametersDescription
muteSets whether to stop subscribing to the audio streams of all remote users.
true: Stop subscribing to the audio streams of all remote users.
false: (Default) Resume subscribing to the audio streams of all remote users.

Returns

setDefaultMuteAllRemoteAudioStreams

Sets whether to receive all remote audio streams by default.

public static int setDefaultMuteAllRemoteAudioStreams(boolean mute)

Parameters

ParametersDescription
mute* True:Stop subscribing to the audio streams of all remote users by default.
* False:(Default) Resume subscribing to the audio streams of all remote users by default.

Returns

Video management

enableVideo

Enable/disable the video module.

public static int enableVideo(boolean enable)

Parameters

ParametersDescription
enabletrue: enable, false: disable

Returns

Details

This method is used to enable/disable the video mode. It can be called before joining a channel or during a call. Call enableVideo(true) before joining a channel, then the video mode is automatically turned on, and enableVideo(true) switches from audio mode to video mode. Call enableVideo(false) to turn off the video mode.

Note

setVideoEncoderConfiguration

Sets the video encoder configuration.

java public static int setVideoEncoderConfiguration(String cameraId, int maxWidth, int maxHeight, int maxFps, int orientationMode)

Parameters

ParametersDescription
cameraIdSpecifies the ID of the camera to be operated. If it is a single camera mode, the Parameters are ignored
maxWidthAllowable maximum width
maxHeightAllowable maximum height
maxFpsMaximum frame rate allowed
orientationModeVideo rotation mode, the value is as follows:

* ORIENTATION_MODE_ADAPTIVE(0), default adaptive;
* ORIENTATION_MODE_FIXED_LANDSCAPE(1), landscape mode
* ORIENTATION_MODE_FIXED_PORTRAIT(2), portrait mode

Returns

Details

This method sets the video encoding Parameters. All the set parameters are the maximum value under ideal conditions. When the video engine cannot reach the maximum resolution or frame rate set due to equipment, network environment, etc., it will take the value closest to the maximum.

startPlayingLocalVideo

Start playing local video.

public static int startPlayingLocalVideo(String cameraId, RtcSurfaceViewRenderer renderer, int renderMode, int mirrorMode)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
rendererView window for displaying video
renderModeDisplay mode, the values are as follows:

* RENDER_MODE_HIDDEN(1), fill the window, the image may be cropped
* RENDER_MODE_FIT( 2), show all, the window may have black borders
mirrorModeMirror mode, the value is as follows:

* VIDEO_MIRROR_MODE_ENABLED(1)
* VIDEO_MIRROR_MODE_DISABLED(2)

Returns

Details

Call this method to start previewing the local video. Need to call enableVideo and enableLocalVideo in advance to start the local camera. When you leave the channel and enter again, you need to call this method again to start previewing the local video again.

Note

If you want to update the display or mirroring mode of the local video during a call, please use the setLocalVideoRenderMode / setLocalVideoMirrorMode method.

startPlayingRemoteVideo

Start playing the remote video.

public static int startPlayingRemoteVideo(String streamId, RtcSurfaceViewRenderer renderer, int renderMode, int mirrorMode)

Parameters

ParametersDescription
streamIdID of the remote video stream
mediaTypeThe media type of the remote stream, the values are as follows:
* MEDIA_TYPE_AUDIO_ONLY(1)
*MEDIA_TYPE_AUDIO_AND_VIDEO(3)
*MEDIA_TYPE_ONLINE_MOVIE_VIDEO(4)
*MEDIA_TYPE_OFFLINE_MOVIE_VIDEO(5)
*MEDIA_TYPE_SCREEN_VIDEO(6)
rendererView window for displaying video
renderModesee startPlayingLocalVideo
mirrorModesee startPlayingLocalVideo

Returns

Details Call this method to start playing the remote video. You need to call enableVideo in advance to enable the video engine.

Note

If you want to update the display or mirroring mode of the remote user’s video during a call, please use the setRemoteVideoRenderMode / setRemoteVideoMirrorMode method.

setLocalVideoRenderMode

Set the display mode of the local video.

public static int setLocalVideoRenderMode(String cameraId, int renderMode)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
renderModesee startPlayingLocalVideo

Returns

Details

After playing the local video, you can call this method to update the display mode of the local video. This method only affects the video images seen by local users, and does not affect the video images published locally.

Note

setLocalVideoMirrorMode

Sets the local video mirror mode.

public static int setLocalVideoMirrorMode(String cameraId, int mirrorMode)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
mirrorModeSee. startPlayingLocalVideo

Returns

Details

After playing the local video, you can call this method to update the mirror mode of the local video. This method only affects the video images seen by the local users, and does not affect the locally published video images.

Note

setRemoteVideoRenderMode

Set the display mode of the remote video.

public static int setRemoteVideoRenderMode(String streamId, int renderMode)

Parameters

ParametersDescription
streamIdID of the remote video stream
renderModeSee startPlayingLocalVideo

Returns

Details

After playing the remote user’s video, you can call this method to update the display mode of the remote user’s video when it is displayed locally. This method only affects the video images seen by local users.

Note

setRemoteVideoMirrorMode

Set the mirror mode of the remote video.

public static int setRemoteVideoMirrorMode(String streamId, int mirrorMode)

Parameters

ParametersDescription
streamIdID of the remote video stream
mirrorModeSee startPlayingLocalVideo

Returns

Details

After playing the remote user’s video, you can call this method to update the mirror mode when the remote user’s video is displayed locally. This method only affects the video images seen by local users.

Note

stopPlayingLocalVideo

Stop playing local video.

public static int stopPlayingLocalVideo(String cameraId)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored

Returns

stopPlayingRemoteVideo

Stop playing the remote video.

public static int stopPlayingRemoteVideo(String streamId)

Parameters

ParametersDescription
streamIdID of the remote video stream
mediaTypeSee startPlayingRemoteVideo

Returns

enableLocalVideo

Disables/Re-enables the local video capture.

public static int enableLocalVideo(String cameraId, boolean enable)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single camera mode, the Parameters are ignored
enableWhether to disable/re-enable the local video, including the capturer, renderer, and sender:
* true: (Default) Re-enable the local video.
* false: Disable the local video. Once the local video is disabled, the remote users can no longer receive the video stream of this user, while this user can still receive the video streams of other remote users. When you set enabled as false, this method does not require a local camera.

Returns

Details

This method disables or re-enables local video capture and does not affect the reception of remote video.

muteLocalVideoStream

Stops or resumes publishing the local video stream.

public static int muteLocalVideoStream(String cameraId,boolean mute)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single camera mode, the Parameters are ignored
mute* true: Stop publishing the local video stream.
* false: Resume publishing the local video stream.

Returns

Details

After the method is successfully called, the remote end will trigger the onRemoteVideoStateChanged callback, the reason is REMOTE_VIDEO_STATE_REASON_REMOTE_MUTED.

Note

When this method is called, the SDK no longer sends the local video stream, but the camera is still working. Compared with enableLocalVideo for controlling the sending of local video streams, this method has a faster response time. This method does not affect the acquisition of local video streams and does not disable the camera.

muteRemoteVideoStream

Stops or resumes subscribing to the video stream of a specified user.

public static int muteRemoteVideoStream(String streamId, boolean mute)

Parameters

ParametersDescription
streamIdID of the remote video stream
mute* true:Stop subscribing to the video stream of a specified user.
* false: (Default) Resume subscribing to the video stream of a specified user.

Returns

Details

After the method is successfully called, the onRemoteVideoStateChanged callback will be triggered locally, and the reason is REMOTE_VIDEO_STATE_REASON_LOCAL_MUTED

muteAllRemoteVideoStreams

Stops or resumes subscribing to the video streams of all remote users.

public static int muteAllRemoteVideoStreams(boolean mute)

Parameters

ParametersDescription
mute* true:Stop subscribing to the video streams of all remote users.
* false:(Default) Resume subscribing to the video streams of all remote users.

Returns

setDefaultMuteAllRemoteVideoStreams

Sets whether to receive all remote video streams by default.

public static int setDefaultMuteAllRemoteVideoStreams (boolean mute)

Parameters

ParametersDescription
mute* true:Stop subscribing to the video streams of all remote users by default.
* false:(Default) Resume subscribing to the video streams of all remote users by default.

Returns

hookLocalVideoFrame

Allow/disable local video data callback.

public static int hookLocalVideoFrame(String cameraId,boolean hook)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
hookWhether to allow local video data callbacks.

* true: allowed
* false: prohibited (default)

Returns

Details

This method controls whether the original video data of the local camera is called back to the application layer, but does not control the start or stop of the collection behavior.

setLocalVideoHD

Set local video HD capture.

public static int setLocalVideoHD(String cameraId)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored

Returns

Details

This method enables high-definition local video capture, but does not affect the size of the video sent to the remote end. The sent video will be cut, stretched, etc., controlled by setVideoEncoderConfiguration.

Video pre-process and post-process

setBeautyEffectOptions

public static int setBeautyEffectOptions(String cameraId, boolean enabled, BeautyOptions options)

Enables/Disables image enhancement and sets the options.

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
enabledWhether to enable image enhancement::

* true:Enables image enhancement.
* false:Disables image enhancement.
optionsThe image enhancement options. See BeautyOptions

Returns

setVideoEffectOptions

public static int setVideoEffectOptions(boolean enabled, Structs.VideoEffectOptions options, String  sourceID)

Set up advanced beauty

Parameters

| Parameters | Description | | ——– | —————————————- ——————– | | enabled | Whether to enable the beauty function:

* true: enable
* false: (default) disable | | options | Beauty options, see VideoEffectOptions for detailed definitions | | sourceID | Specify the SourceID to be operated. If it is a single camera mode, this Parameters is ignored |

Returns

Multi-channel management

createChannel

Create and get an RtcChannel object

public static RtcChannel createChannel(String channelId)
ParametersDescription
channelIdchannel id

Returns

Details

Music file playback

startPlayingMovie

Start playing a music file.

public static int startPlayingMovie(String mediaFile, boolean toPublish, boolean cycle, boolean paused, RtcSurfaceViewRenderer rendererOrNull)

Parameters

ParametersDescription
mediaFileThe path of the music file, which can be a local file or http/https path
toPublishWhether to publish or not
pausedWhether to pause immediately after startup. The default is false
cycleWhether to automatically start from the beginning after playing. The default is false
rendererOrNullIf it is an mp4 video file, the view window used to display the video. Can be null

Returns

stopPlayingMovie

Stop playing a music file.

public static int stopPlayingMovie(String mediaFile)

Parameters

ParametersDescription
mediaFileSee startPlayingMovie for details

Returns

pausePlayingMovie

Pause/resume playing a music file.

public static int pausePlayingMovie(String mediaFile, boolean pause)

Parameters

ParametersDescription
mediaFileSee startPlayingMovie for details
pausetrue to pause playback; false to resume playback

Returns

getMovieInfo

Get information about music files

public static int getMovieInfo(String mediaFile, Structs.LocalMovieInfo info)

Parameters

ParametersDescription
mediaFileSee startPlayingMovie for details
infoMedia file information. See LocalMovieInfo for details

Returns

getMovieCurrentPosition

Get the playback progress of the music file.

public static long getMovieCurrentPosition(String mediaFile)

Parameters

ParametersDescription
mediaFileSee startPlayingMovie for details

Returns

Play progress (in milliseconds)

setMoviePosition

Continue to play a music file.

public static int setMoviePosition(String mediaFile, long pos)

Parameters

ParametersDescription
mediaFileSee startPlayingMovie for details
posThe target time to move, in milliseconds

Returns

Audio file playback

getEffectsVolume

Obtain the playback volume of the sound effect file.

public static int getEffectsVolume()

Returns

setEffectsVolume

Set the playback volume of the sound effect file.

public static int setEffectsVolume(int volume)

Parameters

ParametersDescription
volumeVolume value, the range is [0, 100], the default is 100.

Returns

setVolumeOfEffect

Adjust the playback volume of the sound effect file in real time, the range is [0,100]

public static int setVolumeOfEffect(int soundId, int volume)

Parameters

ParametersDescription
soundIdThe sound effect ID passed in when playEffect.
volumeVolume value, the range is [0, 100], the default is 100.

playEffect

Start playing a sound effect file.

public static int playEffect(int soundId, String filePath, int loopCount,double pitch,double pan, int gain, boolean toPublish, long startTimeMS, long endTimeMS)

Parameters

ParametersDescription
soundIdThe sound effect ID set by yourself must be unique.
filePathThe path of the sound effect file, which can be a local file or an http/https link.
loopCountSet the number of times the sound effect file is played in a loop:

* 0: Play the sound effect file once
* 1: Play the sound effect file twice in a loop
* -1: Infinite loop Play the sound effect file until it stops after calling stopEffect or stopAllEffects
pitchThe pitch of the sound effect. The value range is [0.5,2.0]. The default value is 1.0, which means the original pitch. The smaller the value, the lower the pitch.
panThe spatial position of the sound effect. The value range is [-1.0,1.0]
-1.0: The sound effect appears on the left.
0.0: The sound effect appears right in front.
1.0: The sound effect appears on the right.
gainSet the volume of the sound effect. The value range is [0.0,100.0]. The default value is 100.0. The smaller the value, the lower the volume of the sound effect.
toPublishSet whether to transmit the sound effect to the remote site

* true: While the sound effect file is played locally, the remote user can also hear the sound effect
* false: only locally Hear the sound effect
startTimeMSSet the time (milliseconds) to start playing, and the file will start playing from there.
endTimeMSSet the time (milliseconds) to end the playback, and the file will end when it is played.

Returns

Details

This method can play a designated local or online sound effect file to add sound effects to the application, such as the sound effects of specific operations in the game.

In this method, you can set the number of times and gain of the sound effect file, and whether the remote user can hear the sound effect. You can call this method multiple times. By passing in the soundID and filePath of different sound effect files, multiple sound effect files can be played at the same time to achieve sound effect superimposition. For the best user experience, we recommend that no more than 3 sound effect files are played at the same time.

After calling this method to play the sound effect, the onAudioEffectFinish callback will be triggered.

stopEffect

Stop playing a sound file.

public static int stopEffect(int soundId)

Parameters

ParametersDescription
soundIdThe sound effect ID passed in when playEffect.

Returns

stopAllEffects

Stop playing all sound effect files.

public static int stopAllEffects()

Returns

preloadEffect

Preload the specified sound effect file into the memory.

public static int preloadEffect (int soundId, String filePath)

Parameters

ParametersDescription
soundIdThe sound effect ID set by yourself must be unique.
filePathThe path of the sound effect file, which can be a local file or an http/https link.

Returns

unloadEffect

Release a preloaded sound effect file from the memory.

public static int unloadEffect (int soundId)

Parameters

ParametersDescription
soundIdThe sound effect ID set by yourself must be unique.

Returns

pauseEffect

Pause playing a sound effect file.

public static int pauseEffect(int soundId)

Parameters

ParametersDescription
soundIdThe sound effect ID passed in when playEffect.

Returns

pauseAllEffects

Pause all sound effect files.

public static int pauseAllEffects()

Returns

resumeEffect

Continue to play a sound effect file.

public static int resumeEffect(int soundId)

Parameters

ParametersDescription
soundIdThe sound effect ID passed in when playEffect.

Returns

resumeAllEffects

Resume all sound effect files.

public static int resumeAllEffects()

Returns

Vocal effect

To use this feature, please contact us to help you activate

setAudioQuality

Set the audio quality of the local transmission

Parameters

ParameterDescription
qualityAudio quality, see AUDIO_QUALITY

Returns

setLocalVoicePitch

Changes the voice pitch of the local speaker.

public static int setLocalVoicePitch(double pitch)

Parameters

ParametersDescription
pitchSets the voice pitch. The value ranges between 0.5 and 2.0. The lower the value, the lower the voice pitch. The default value is 1.0 (no change to the local voice pitch).

Returns

setLocalVoiceEqualization

Sets the local voice equalization effect.

public static int setLocalVoiceEqualization(int bandFrequency, int gain)

Parameters

ParametersDescription
bandFrequencySets the band frequency. The value ranges between 0 and 9; representing the respective 10-band center frequencies of the voice effects, including 31, 62, 125, 250, 500, 1k, 2k, 4k, 8k, and 16k Hz.See AUDIO_EQUALIZATION_BAND_FREQUENCY.
gainSets the gain of each band (dB). The value ranges between -15 and 15. The default value is 0.

Returns

setLocalVoiceReverb

Sets the local voice reverberation.

public static int setLocalVoiceReverb(int reverbType, double value)

Parameters

Parametersdescribe
reverbTypeThe reverberation key For details. see AUDIO_REVERB_TYPE
valueSet the effect value of the reverberation effect. For the value range of each reverberation effect, please refer to AUDIO_REVERB_TYPE

Returns

setAudioEffectPreset

Sets an SDK preset audio effect.

public static int setAudioEffectPreset(int preset)
ParametersDescription
presetThe options for SDK preset audio effects. See AUDIO_EFFECT_PRESET

Returns

Details

This method sets the human voice effect preset by the SDK. This method needs to be called after enableLocalAudio. Note that calling the enableLocalAudio interface and passing false will cancel the preset sound effect. This method cannot be mixed with setLocalVoicePitch, setLocalVoiceEqualization, setLocalVoiceReverb.

enableDeepLearningDenoise

Enables or disables deep-learning noise reduction.

public static int enableDeepLearningDenoise(boolean enabled)

Parameters

ParametersDescription
enabledSets whether to enable deep-learning noise reduction.:
true: (Default) Enables deep-learning noise reduction.
false: Disables deep-learning noise reduction.

Returns

Sound localization

enableSoundPositionIndication

Enables/Disables stereo panning for remote users.

public static int enableSoundPositionIndication(boolean enabled)

Parameters

ParametersDescription
enabledtrue:Enables stereo panning.
false:Disables stereo panning.

Returns

Details

If you want to call setRemoteVoicePosition to realize the function of listening voice position recognition, please make sure to call this method to turn on the voice stereo of the remote user before enableAudio

setRemoteVoicePosition

Sets the sound position of a remote user.

public static int setRemoteVoicePosition(String uid, double pan, double gain)

Parameters

ParametersDescription
uidThe ID of the remote user.
panThe sound position of the remote user. The value ranges from -1.0 to 1.0:
•0.0:the remote sound comes from the front.
• -1.0:the remote sound comes from the left.
• 1.0:the remote sound comes from the right.
gainGain of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original gain of the remote user). The smaller the value, the less the gain.

Returns

Details

Cross-channel media stream forwarding

startChannelMediaRelay

Starts to relay media streams across channels.

public static int startChannelMediaRelay(Structs.ChannelMediaRelayConfiguration config)

Parameters

ParametersDescription
configThe configuration of the media stream relay: ChannelMediaRelayConfiguration

Returns

Details

After a successful method call, the SDK triggers the onChannelMediaRelayStateChanged callbacks, and these callbacks return the state and events of the media stream relay.

Note

updateChannelMediaRelay

Updates the channels for media relay.

public static int updateChannelMediaRelay(Structs.ChannelMediaRelayConfiguration config)

Parameters

ParametersDescription
configThe media stream relay configuration: ChannelMediaRelayConfiguration

Returns

Details

After successfully starting to forward the media stream across channels, if you want to forward the stream to multiple target channels, or exit the current forwarding channel, you can call this method.

Note

stopChannelMediaRelay

Stops the media stream relay.

public static int stopChannelMediaRelay()

Returns

Details

If the method call fails, the SDK triggers the onChannelMediaRelayStateChanged callback with the RELAY_ERROR_SERVER_NO_RESPONSE(2) or RELAY_ERROR_SERVER_CONNECTION_LOST(8) error code. You can leave the channel by calling the leaveChannel method, and the media stream relay automatically stops.

Volume indication

enableAudioVolumeIndication

Enable/disable the speaker volume prompt.

public static int enableAudioVolumeIndication(int interval)

Parameters

ParametersDescription
intervalSets the time interval between two consecutive volume indications:

* <= 0: Disables the volume indication.
* > 0: Time interval (ms) between two consecutive volume indications. We recommend setting interval ≥ 200 ms.

Returns

Switch speakers or earpieces

setEnableSpeakerphone

Enables/Disables the audio route to the speakerphone.

public static int setEnableSpeakerphone(boolean enabled)

Parameters

ParametersDescription
enabledSets whether to enable the speakerphone or earpiece
true: Enable the speakerphone. The audio route is the speakerphone.
false: Disable the speakerphone. The audio route is the earpiece.

Returns

Details

This method sets whether to allow the voice to be routed to the speaker (external amplifier). This method can be called before joinChannel.

isSpeakerphoneEnabled

Checks whether the speakerphone is enabled.

public static boolean isSpeakerphoneEnabled()

Returns

Details

When a wired or Bluetooth headset is connected, the sound will be automatically switched to the headset. At this time, the Returns value of isSpeakerphoneEnabled is still the setting before the headset is connected. When the headset is disconnected, the sound will also return to the playback path set before the headset is connected.

In-ear monitoring

enableInEarMonitoring

Enables in-ear monitoring.

public static int enableInEarMonitoring(boolean enabled)

Parameters

ParametersDescription
enabledSets whether to enable/disable in-ear monitoring:
true: Enable
false: (Default) Disable.

Returns

Note

Users must use wired headphones to hear the ear-back effect

setInEarMonitoringVolume

Sets the volume of the in-ear monitor.

public static int setInEarMonitoringVolume(int volume)

Parameters

ParametersDescription
volumeSets the volume of the in-ear monitor. The value ranges between 0 and 100 (default).

Returns

Network test before call

startEchoTest

Starts an audio call test.

public static int startEchoTest(int intervalInSeconds)

Parameters

ParametersDescription
intervalInSecondsThe time interval of the test result of the voice call loop, the value range is [2,10], and the unit is second.

Returns

Details

Need to call enableVideo and enableAudio in advance

stopEchoTest

Stops the audio call test.

public static int stopEchoTest()

Returns

startLastmileProbeTest

Starts the last-mile network probe test before joining a channel to get the uplink and downlink last-mile network statistics, including the bandwidth, packet loss, jitter, and round-trip time (RTT).

public static int startLastmileProbeTest(Structs.LastmileProbeConfig config)

Parameters

ParametersDescription
configSee LastmileProbeConfig

Returns

Details

The network quality detection before the call starts, and the bandwidth, packet loss, network jitter, and round-trip delay data of the uplink and downlink networks are fed back to the user. After enabling this method, the SDK will Returns the following 2 callbacks in turn:

Note Please perform this test before joining the channel. Need to call enableVideo and enableAudio in advance.

stopLastmileProbeTest

Stops the last-mile network probe test.

public static int stopLastmileProbeTest()

Returns

Server recording

When someone in the channel calls the start/stop/pause/resume server recording interface and the server recording state changes, everyone in the channel will receive the onServerRecordStateChange callback notify.

When the room is in recording/recording paused two states, new people entering the room will also receive onServerRecordStateChange callback notification.

Audio capture (Push mode only)

setExternalAudioSource

public static int setExternalAudioSourceParameters(int sampleRate, int channels)

Sets the external audio source.

This method sets the external audio format passed in pushAudioFrame.

Details This method needs to be called before joining the channel.

Parameters

ParametersDescription
sampleRateThe sample rate (Hz) of the external audio source, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
channelsThe number of channels of the external audio source:(1: Mono. 2: Stereo.)

Returns

pushSourceAudioFrame

public static int pushSourceAudioFrame(byte[] data)

To push external audio frames, you need to call setRecordingAudioFrameParameters first.

Parameters

ParametersDescription
dataValid data of the frame

Returns

Audio self-rendering (Pull mode only)

pullPlaybackAudioFrame

Pulls the remote audio frame.

public static int pullPlaybackAudioFrame(byte[] data10ms)

Pull playback (after mixing) data (pulling 10ms data at a time) (the user needs to continue to call at 10ms intervals). Need to call setPlaybackAudioFrameParameters first.

After calling this method, the App will take an active pull method to obtain the remote-end decoded and mixed audio data for audio playback.

Parameters

ParametersDescription
data10ms10ms effective frame data

Returns

setExternalAudioSink

Sets the external audio sink.

public static int setExternalAudioSinkParameters(int sampleRate, int channels)

Set the data format pulled by pullAudioFrame. This method sets the audio format pulled by pullAudioFrame.

Details Ensure that you call this method before joining a channel.

Parameters

ParametersDescription
sampleRateThe sample rate (Hz) of the external audio sink. You can set this parameter as 16000, 32000, 44100, or 48000.
channelThe number of audio channels of the external audio sink: (1: Mono 2: Stereo

Returns

Original audio data

setRecordingAudioFrameParameters

Sets the audio sampling format for the onRecordAudioFrame callback.

public static int setRecordingAudioFrameParameters(int sampleRate, int channel, int samplesPerCall)

Details Ensure that you call this method before joining a channel.

Parameters

ParametersDescription
sampleRateThe sample rate (samplesPerSec) returned in the onRecordFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
channelThe number of audio channels (channels) returned in the onRecordFrame callback: (1: Mono . 2: Stereo)
samplesPerCallThe number of samples the onRecordFrame callback returns. In RTMP or RTMPS streaming scenarios, set it as 1024.

Returns

setPlaybackAudioFrameParameters

Sets the audio playback format for the OnPlaybackAudioFrame callback.

public static int setPlaybackAudioFrameParameters(int sampleRate, int channel, int samplesPerCall) 

Details Ensure that you call this method before joining a channel.

Parameters

ParametersDescription
sampleRateThe sample rate (samplesPerSec) returned in the onPlaybackFrame callback, which can be set as 8000, 16000, 32000, 44100, or 48000 Hz.
channelThe number of channels (channels) returned in the onPlaybackFrame callback:(1: Mono 2: Stereo
samplesPerCallThe number of samples the onPlaybackFrame callback returns. In RTMP or RTMPS streaming scenarios, set it as 1024.

Returns

Record sound clip

startRecordingVoiceClip

Start recording a sound clip

public static int startRecordingVoiceClip(String clipBaseName, int clipDurationSeconds, int fileType)

Parameters

ParametersDescription
clipBaseNameSound clip basename
clipDurationSecondsDuration of each sound clip
fileTypeFile Type MEDIAFILE_TYPE

Returns

Details

After the call is successful, the user will receive the onVoiceClipFileReady callback.

stopRecordingVoiceClip

Stop recording a sound clip

public static int stopRecordingVoiceClip(String clipBaseName)

Parameters

ParametersDescription
clipBaseNameSound clip basename

Returns

Switch cameras

switchCamera

Switches between front and rear cameras.

public static int switchCamera()

Returns

Details

This method is only applicable to single camera mode. Please call this method when local video capture is turned on.

isFrontFacingCameraFired

Determine whether it is a front camera

public static boolean isFrontFacingCameraFired(String cameraId)
ParametersDescription
cameraIdDevice id

Returns

setCameraFlipMode

Set the flip mode of the camera.

public static int setCameraFlipMode(String cameraId, boolean horizontalFlip, boolean verticalFlip)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
horizontalFlipWhether to enable horizontal flip
verticalFlipWhether to enable vertical flip

Returns

Details

This method flips the data collected by the camera horizontally (and/or vertically). For the same camera, after turning off the camera, the engine will still remember the camera’s flip settings, and the previous settings will be automatically loaded when the camera is turned on next time, unless the user passes enableVideo(false) The video engine has been turned off.

correctCameraKeystoning

Correct the keystone distortion of the camera.

public static int correctCameraKeystoning(String cameraId, float fromX, float fromY, float toX, float toY)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored
fromX,fromYThe coordinates of the starting point of the vector for this correction
toX,toYThe vector end point coordinates of this correction

Returns

Details

This method corrects the keystone distortion of the camera through the incremental interactive mode. The vector AB formed by the starting point A (fromX, fromY) and the end point B (toX, toY) represents the displacement of this correction, which is equivalent to the user dragging the mouse to move from A to B. The engine will automatically determine this time according to the position of the starting point A Which corner of the picture is the corrected corner point.

The coordinates of the upper left and lower right corners of the view are (0.0, 0.0) and (1.0, 1.0). The view is divided into four equally divided 1/4 areas, namely the upper left area, the upper right area, the lower right area, and the lower left area. Point A and Point B must be located in a certain equally divided area of the view, and cross-area correction is invalid.

resetCameraKeystoning

Cancel the correction of keystone distortion of the camera.

java public static int resetCameraKeystoning(String cameraId)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be operated. If it is a single-camera mode, this Parameters is ignored

Returns

Details

This method disables the keystone correction function of the camera and restores the default behavior.

getLocalCameraIds

Get a list of local camera IDs.

public String[] getLocalCameraIds()

Returns

Details

In multi-camera mode, you can use this method to enumerate all the cameras, and then open one or more of them for publishing.

Stream message

sendStreamMessage

The SDK has the following restrictions on this method:

Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 kB. Each client can send up to 6 kB of data per second. Each user can have up to five data channels simultaneously. A successful onStreamMessage method call triggers the onStreamMessage callback on the remote client, from which the remote user gets the stream message.

public static int sendStreamMessage( byte[] message ) 

Parameters

ParametersDescription
messageSent data.

Returns

Publish management

setPublishStreamInfo

setPublishStreamInfo(String streamInfo, String cameraId)

Set local video information

Parameters

ParameterDescription
streamInfoLocal video information (json format)
cameraIdSpecify the camera ID to be published. If it is a single camera mode, this Parameters is ignored

Returns

Details

Bind the information describing the video stream to the device so that others can receive it. If you have this requirement, it must be called before publishStream after joinChannel succeeds. If the remote end successfully subscribes to this video stream, the information of this video stream will be reflected in the streamInfoParameters in the onRemoteVideoStateChanged callback.

publishStream

Start to publish local audio and video.

public static int publishStream(String cameraId))

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be published. If it is a single camera mode, this Parameters is ignored

Returns

Details

Publish your own audio and video to the channel for others to watch and listen. After the release is successful, the local will receive the onLocalVideoStateChanged callback. If the remote end turns off automatic subscription (see setAutoSubscribe for details), it will receive a onUserPublished callback. At this time, if the other party decides to watch this person, they need to call subscribeStream, and after success, they will receive the onRemoteVideoStateChanged callback. If the remote end does not turn off the automatic subscription, it will directly receive the onRemoteVideoStateChanged callback.

Note

This method can only be called after joining the channel successfully.

unpublishStream

Stop publishing local audio and video.

public static int unpublishStream(String cameraId)

Parameters

ParametersDescription
cameraIdSpecify the camera ID to be published. If it is a single camera mode, this Parameters is ignored

Returns

Details

Stop publishing your own audio and video. After you stop publishing, you will receive the onLocalVideoStateChanged callback locally. If the remote end turns off automatic subscription (see setAutoSubscribe for details), it will receive a onUserUnpublished callback. In addition, the onRemoteVideoStateChanged callback will be received regardless of whether the automatic subscription is turned off by the remote end.

Note

This method can only be called after joining the channel successfully.

Subscription management (only for manual subscription mode)

subscribeStream

Start subscribing to one audio and video.

public static int subscribeStream(String streamId)

Parameters

ParametersDescription
streamIdThe unique ID of the audio and video stream in the channel. This ID can be obtained from the onUserPublished callback

Returns

Details

Please call after receiving the onUserPublished callback.

unsubscribeStream

Stop subscribing to one audio and video.

public static int unsubscribeStream(String streamId)

Parameters

ParametersDescription
streamIdThe unique ID of the audio and video stream in the channel. This ID can be obtained from the onUserPublished / onUserUnpublished callback

Returns

Details

After receiving the onUserPublished callback, you can call subscribeStream / unsubscribeStream repeatedly /#unsubscribestream) method to create/remove subscription to this audio and video stream. After receiving the onUserUnpublished callback, there is no need to manually call the unsubscribe method.

setAutoSubscribe

Turn on/off the automatic subscription mode (enabled by default).

public static int setAutoSubscribe(boolean autoSubscribe)

Parameters

ParametersDescription
autoSubscribeWhether to enable automatic subscription mode

Returns

Details

If the automatic subscription mode is turned on, whenever a new media stream is released in the channel, the local SDK will automatically complete the network link establishment and the decoding of audio and video data, and trigger onRemoteVideoStateChanged callback (the state is REMOTE_VIDEO_STATE_STARTING), you only need to call the corresponding playback method at this time. If the automatic subscription mode is turned off, whenever a new media stream is published in the channel, only onUserPublished callback will be received locally, and the link will not be triggered automatically The beginning of creation and data decoding. Developers can decide whether/when to subscribe.

Server recording

startServerRecord

Start server recording.

public static int startServerRecord()

Returns

stopServerRecord

Stop server recording.

public static int stopServerRecord()

Returns

pauseServerRecord

Pause server recording.

public static int pauseServerRecord()

Returns

resumeServerRecord

Resume server recording.

public static int resumeServerRecord()

Returns

Advanced signaling method

These methods must be called after successfully joining the channel.

setProperty

Set custom attributes for a user in the channel.

public static int setProperty(String uid, String tellWhom, String properties)

Parameters

ParametersDescription
uiduid of the target user
tellWhomThe user to be notified. Empty to notify everyone in the channel. If you specify the uid of a user, only the specified user will be notified. Default is empty
propertiesCustom properties, must be a json string

Returns

Details

There are two ways to set custom attributes:

After the setting is successful, both the notified user and the set user will receive the notification. In addition, new users entering the channel will also get these attributes of the user in the onUserJoined callback.

Note

sendChatMsg

Send chat messages.

public static int sendChatMsg(String toId, String message, String extraData)

Parameters

ParametersDescription
toIdThe user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the specified notification user will be notified
messageChat message text
extraDataCustom attributes of this message. Must be a json string. Can be empty

Returns

Details

You can usually use extraData to transfer some information such as fonts and avatars. Users in the channel will receive the onChatMessageArrival callback.

pubMsg

Post a custom message.

public static int pubMsg(String msgId,
String msgName,
String toId,
String data,
String associatedUserId,
String associatedMsgId,
boolean save,
String extendInfo)

Parameters

ParametersDescription
msgIdMessage id, which is the unique identifier of a message in the channel
msgNameMessage name
toIdThe user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the user specified to be notified will be notified
dataMessage content. Must be a json string. Can be empty
associatedUserIdThe uid of the associated user, once a message is associated with a user, the message will be automatically deleted when the user logs out
associatedMsgIdThe id of the associated message. Once a message is associated with another message, the associated message will be deleted automatically when the associated message is deleted.
saveWhether to save. If saved, users who enter the channel later will receive this signaling in the onPubMsg callback until this message is deleted by the delMsg method
extendInfoReserved Parameters

Returns

Details

The pubMsg mechanism is similar to a message board, which is used to save and synchronize the business status in the channel. Both users who are already in the channel or new users who join later can receive custom messages that have been published in the current channel through the onPubMsg callback.

delMsg

Delete a custom message.

public static int delMsg(String msgId, String msgName, String toId, String data)

Parameters

ParametersDescription
msgIdThe message id to be deleted. When publishing a message through the pubMsg method, its id will be specified
msgNameMessage name
toIdThe user to be notified. Empty to notify everyone in the channel. If the uid of a certain user is specified, only the specified notification user will be notified.
dataReserved Parameters

Returns

Details

After the call is successful, users already in the channel will receive the message onDelMsg.

Note

Deleting a non-existent message will fail.

evictUser

Kick a user out of the channel.

public static int evictUser(String uid, int reason)

Parameters

ParametersDescription
uidThe uid of the kicked user
reasoncustom field

Returns

Details

After the call is successful, the kicked user will receive the onLocalUserEvicted callback. Other users will receive the onUserLeft callback.

CDN push streaming

addPublishStreamUrl

Publishes the local stream to a specified CDN streaming URL.

public static int addPublishStreamUrl(String url)

Parameters

ParametersDescription
urlThe CDN streaming URL in the RTMP or RTMPS format. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters.

Returns

removePublishStreamUrl

Removes an RTMP or RTMPS stream from the CDN.

public static int removePublishStreamUrl(String url)

Parameters

ParametersDescription
urlThe CDN streaming URL to be removed. The maximum length of this parameter is 1024 bytes. The URL address must not contain special characters, such as Chinese language characters.

Returns

setLiveTranscoding

Sets the video layout and audio settings for CDN live.

public static int setLiveTranscoding(Structs.LiveTranscoding transcoding)

Parameters

ParametersDescription
transcodingThe CDN live audio/video transcoding settings. See LiveTranscoding

Returns

Other methods

getSdkVersion

Gets the SDK version.

public static String getSdkVersion()

Returns

The current version number.