VideoCall
) and audio call (AudioCall
) are the call modes, and interactive video streaming (Live
) and interactive audio streaming (VoiceChatRoom
) are the live streaming modes.
The call modes allow a maximum of 300 users in each TRTC room, and up to 50 of them can speak at the same time. The call modes are suitable for scenarios such as one-to-one video calls, video conferencing with up to 300 participants, online medical consultation, remote interviews, video customer service, and online Werewolf playing.TRTC-API-Example
, which offers sample code for your reference. Use Android Studio to open your project and follow the steps below to modify the app/build.gradle
file.dependencies
.dependencies {compile 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'}
defaultConfig
, specify the CPU architecture to be used by your application.defaultConfig {ndk {abiFilters "armeabi-v7a", "arm64-v8a"}}
AndroidManifest.xml
.<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.RECORD_AUDIO" /><uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.READ_PHONE_STATE" /><uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /><uses-permission android:name="android.permission.BLUETOOTH" /><uses-feature android:name="android.hardware.camera" /><uses-feature android:name="android.hardware.camera.autofocus" />
TRTCCloud
instance.// Create a `TRTCCloud` instancemTRTCCloud = TRTCCloud.sharedInstance(getApplicationContext());mTRTCCloud.setListener(new TRTCCloudListener(){// Processing callbacks...});
setListener
to subscribe to event callbacks and listen for event and error notifications.// Error notifications indicate that the SDK has stopped working and therefore must be listened for@Overridepublic void onError(int errCode, String errMsg, Bundle extraInfo) {Log.d(TAG, "sdk callback onError");if (activity != null) {Toast.makeText(activity, "onError: " + errMsg + "[" + errCode+ "]" , Toast.LENGTH_SHORT).show();if (errCode == TXLiteAVCode.ERR_ROOM_ENTER_FAIL) {activity.exitRoom();}}}
TRTCParams
Parameter | Type | Description | Example |
sdkAppId | Number | 1400000123 | |
userId | String | Can contain only letters (a-z and A-Z), digits (0-9), underscores, and hyphens. We recommend you set it based on your business account system. | test_user_001 |
userSig | String | eJyrVareCeYrSy1SslI... | |
roomId | Number | Numeric room ID. For string-type room ID, use strRoomId in TRTCParams . | 29834 |
userID
cannot be in the same room at the same time as it will cause a conflict.roomId
in the TRTCParams
parameter. If the room does not exist, the SDK will automatically create it with the roomId
value as the room number.appScene
parameter according to your actual application scenario. Inappropriate appScene
values may lead to increased lag or decreased clarity.TRTC_APP_SCENE_VIDEOCALL
.TRTC_APP_SCENE_AUDIOCALL
.onEnterRoom(result)
callback. If result
is greater than 0, room entry succeeds, and the value of result
indicates the time (ms) room entry takes; if result
is less than 0, room entry fails, and the value is the error code for the failure.public void enterRoom() {TRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();trtcParams.sdkAppId = sdkappid;trtcParams.userId = userid;trtcParams.roomId = 908;trtcParams.userSig = usersig;mTRTCCloud.enterRoom(trtcParams, TRTC_APP_SCENE_VIDEOCALL);}@Overridepublic void onEnterRoom(long result) {if (result > 0) {toastTip("Entered room successfully; the total time used is [\\(result)] ms")} else {toastTip("Failed to enter the room; the error code is [\\(result)]")}}
onError
event and return the parameters errCode
(error code), errMsg
(error message), and extraInfo
(reserved parameter).exitRoom
to exit the room before entering another room.appScene
must be the same on each client. Inconsistent appScene
may cause unexpected problems.userId
), or muteAllRemoteAudio(true) to mute all remote users. The SDK will stop pulling the audio data of the user(s).view
by calling the startRemoteView(userId, view) method.Fill
: aspect fill. The image may be scaled up and cropped, but there are no black bars.Fit
: aspect fit. The image may be scaled down to ensure that it’s displayed in its entirety, and there may be black bars.userId
) or stopAllRemoteView() to block the video data of all remote users. The SDK will stop pulling the video data of the user(s).@Overridepublic void onUserVideoAvailable(String userId, boolean available) {TXCloudVideoView remoteView = remoteViewDic[userId];if (available) {mTRTCCloud.startRemoteView(userId, remoteView);mTRTCCloud.setRemoteViewFillMode(userId, TRTC_VIDEO_RENDER_MODE_FIT);} else {mTRTCCloud.stopRemoteView(userId);}}
startRemoteView()
to subscribe to the video stream immediately after receiving the onUserVideoAvailable()
event callback, the SDK will stop pulling the remote video within 5 seconds.Fill
: aspect fill. The image may be scaled up and cropped, but there are no black bars.Fit
: aspect fit. The image may be scaled down to ensure that it’s displayed in its entirety, and there may be black bars.// Sample code: publish the local audio/video streammTRTCCloud.setLocalViewFillMode(TRTC_VIDEO_RENDER_MODE_FIT);mTRTCCloud.startLocalPreview(mIsFrontCamera, mLocalView);mTRTCCloud.startLocalAudio();
// Please wait for the `onExitRoom` callback after calling the room exit API.mTRTCCloud.exitRoom()@Overridepublic void onExitRoom(int reason) {Log.i(TAG, "onExitRoom: reason = " + reason);}
onExitRoom
callback to start other SDKs; otherwise, the device busy error may occur.
Was this page helpful?