TUIRoom
is an open-source UI component for audio/video communication. With just a few lines of code changes, you can integrate it into your project to implement screen sharing, beauty filters, low-latency video calls, and other features. In addition to the Android component, we also offer components for iOS, Windows, macOS, and more. |
TUIRoom
componenttuiroom
and debug
, and tuibeauty
folders in the Android
directory to your project. Then, do the following to import the component:setting.gradle
:include ':tuiroom'include ':debug'include ':tuibeauty'
tuiroom
, debug
, and tuibeauty
to the build.gradle
file in app
:api project(':tuiroom')api project(':debug')api project(':tuibeauty')
liteavSdk
) and Chat SDK (imsdk
) dependencies in build.gradle
in the root directory:ext {liteavSdk = "com.tencent.liteav:LiteAVSDK_TRTC:latest.release"imSdk = "com.tencent.imsdk:imsdk-plus:latest.release"}
AndroidManifest.xml
. The SDKs need the following permissions (on Android 6.0 and later, the mic permission must be requested at runtime.)<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.RECORD_AUDIO" /><uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /><uses-permission android:name="android.permission.CAMERA" /><uses-feature android:name="android.hardware.camera"/><uses-feature android:name="android.hardware.camera.autofocus" />
proguard-rules.pro
file, add the SDK classes to the "do not obfuscate" list.-keep class com.tencent.** { *;}
// 1. Log in to the componentTUILogin.addLoginListener(new TUILoginListener() {@Overridepublic void onKickedOffline() { // Callback for forced logout (for example, due to login from another device)}@Overridepublic void onUserSigExpired() { // Callback for `userSig` expiration}});TUILogin.login(context, "Your SDKAppId", "Your userId", "Your userSig", null);// 2. Initialize the `TUIRoom` instanceTUIRoom tuiRoom = TUIRoom.sharedInstance(this);
SDKAppID
.
SDKAppID
. You can view your application’s secret key on the Application Management page of the TRTC console.SDKAppID
, userId
, and Secretkey
. You can click here to quickly generate a UserSig
for testing. For more information, see UserSig.tuiRoom.createRoom(12345, TUIRoomCoreDef.SpeechMode.FREE_SPEECH, true, true);
tuiRoom.enterRoom(12345, true, true);
// 1. The room owner calls the API below to close the room.mTUIRoomCore.destroyRoom(new TUIRoomCoreCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {}});Other users in the room will receive the `onDestroyRoom` callback.@Overridepublic void onDestroyRoom() {// The room owner closes and exits the room.}
// 1. A user (not the room owner) calls the API below to leave the room.mTUIRoomCore.leaveRoom(new TUIRoomCoreCallback.ActionCallback() {@Overridepublic void onCallback(int code, String msg) {}});Other users in the room will receive the `onRemoteUserLeave` callback.@Overridepublic void onRemoteUserLeave(String userId) {Log.d(TAG, "onRemoteUserLeave userId: " + userId);}
// 1. Add the SDK’s screen sharing activity and permission in `AndroidManifest.xml`<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /><application><activityandroid:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"android:theme="@android:style/Theme.Translucent" /></application>// 2. Request the floating window permission in your UIif (Build.VERSION.SDK_INT >= 23) {if (!Settings.canDrawOverlays(getApplicationContext())) {Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));startActivityForResult(intent, 100);} else {startScreenCapture();}} else {startScreenCapture();}// 3. System callback resultprotected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == 100) {if (Build.VERSION.SDK_INT >= 23) {if (Settings.canDrawOverlays(this)) {// The user grants the permission.startScreenCapture();} else {}}}}// 4. Start screen sharingprivate void startScreenCapture() {TRTCCloudDef.TRTCVideoEncParam encParams = new TRTCCloudDef.TRTCVideoEncParam();encParams.videoResolution = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_1280_720;encParams.videoResolutionMode = TRTCCloudDef.TRTC_VIDEO_RESOLUTION_MODE_PORTRAIT;encParams.videoFps = 10;encParams.enableAdjustRes = false;encParams.videoBitrate = 1200;TRTCCloudDef.TRTCScreenShareParams params = new TRTCCloudDef.TRTCScreenShareParams();mTUIRoom.stopCameraPreview();mTUIRoom.startScreenCapture(encParams, params);}
Was this page helpful?