This article will guide you through the process of integrating the TUILiveKit component in a short time. Following this document, you will complete several key steps within an hour and ultimately obtain a voice room feature with a complete UI interface.
Anchor
Audience
Environment Preparations
Android 5.0 (SDK API level 21) or above.
Android Studio 7.0 or above.
Devices with Android 5.0 or above.
Step 1. Activate the service
Before using the Audio and Video Services provided by Tencent Cloud, you need to go to the Console and activate the service for your application. For detailed steps, refer to Activate the service.
Step 2: Download TUILiveKit component
Clone/download the code in Github , and then copy the tuilivekit subdirectory in the Android directory to the same level directory as the app in your current project, as shown below:
Step 3: Project configuration
1. In the root directory of the project, add the jitpack repository URL to the settings.gradle.kts (or settings.gradle) file: Add the jitpack repository dependency (to download the SVG animation library for playing gifts, SVGAPlayer):
2. In the root directory of the project, add the following code to the settings.gradle.kts (or settings.gradle) file. It will import the tuilivekit component downloaded in Step 2 into your current project:
settings.gradle.kts
settings.gradle
include(":tuilivekit:livekit")
include(":tuilivekit:component:common")
include(":tuilivekit:component:barrage")
include(":tuilivekit:component:gift")
include(":tuilivekit:component:audioeffect")
include(":tuilivekit:component:audiencelist")
include(":tuilivekit:component:dashboard")
include(":tuilivekit:component:music")
include(":tuilivekit:component:roominfo")
include(":tuilivekit:livestreamcore")
include(":tuilivekit:voiceroomcore")
include ':tuilivekit:livekit'
include ':tuilivekit:component:common'
include ':tuilivekit:component:barrage'
include ':tuilivekit:component:gift'
include ':tuilivekit:component:audioeffect'
include ':tuilivekit:component:audiencelist'
include ':tuilivekit:component:dashboard'
include ':tuilivekit:component:music'
include ':tuilivekit:component:roominfo'
include ':tuilivekit:livestreamcore'
include ':tuilivekit:voiceroomcore'
3. In the app directory, find the build.gradle.kts (or build.gradle) file and add the following code. It declares the dependency of the current app on the newly added tuilivekit component:
build.gradle.kts
build.gradle
api(project(":tuilivekit:livekit"))
api project(':tuilivekit:livekit')
Note:
The TUILiveKit project already has default dependencies on TRTC SDK, IM SDK, tuiroomengine, and the common library tuicore. Developers do not need to configure them separately. To upgrade the version, modify the tuilivekit/build.gradle file.
4. As the SDK uses Java's reflection feature internally, you need to add certain classes in the SDK to the obfuscation allowlist by adding the following code to the proguard-rules.pro file:
-keep class com.tencent.**{*;}
-keep class com.trtc.uikit.livekit.livestreamcore.**{*;}
-keep class com.trtc.uikit.component.gift.store.model.**{*;}
-keep class com.squareup.wire.**{*;}
-keep class com.opensource.svgaplayer.proto.**{*;}
5. In the app directory, find the AndroidManifest.xml file and add tools:replace="android:allowBackup" to the application node to override internal component settings with your own.
// app/src/main/AndroidManifest.xml
<application
...
// Add the following configuration to override the settings in the dependent SDK
Add the following code to your project. It calls the relevant interfaces in TUICore to complete the TUI component log in to. This step is crucial; you can only use the features provided by TUILiveKit after successfully logging in.
Kotlin
Java
// log in to TUILogin.login(applicationContext,1400000001,// Please replace with the SDKAppID obtained in step one"denny",// Please replace with your UserID"xxxxxxxxxxx",// You can calculate a UserSig in the console and fill it in here
object :TUICallback(){
override fun onSuccess(){Log.i(TAG,"login success")}
override fun onError(errorCode:Int, errorMessage:String){Log.e(TAG,"login failed, errorCode: $errorCode msg:$errorMessage")}})
// Log in
TUILogin.login(context,
1400000001,// Please replace with the SDKAppID obtained in Step 1
"denny",// Please replace with your UserID
"xxxxxxxxxxx",// You can calculate a UserSig in the console and fill it in here
Parameter Description
Here is a detailed introduction to several key parameters needed in the login function:
Parameter
Type
Description
SDKAppID
int
In the final step of step one, you have already obtained it, so it will not be repeated here.
UserID
String
The ID of the current user, string type, is only allowed to contain letters (a-z and A-Z), numbers (0-9), hyphens, and underscores.
userSig
String
Use the SecretKey obtained in Step One, Step 3 to encrypt information such as SDKAppID and UserID to obtain UserSig, which is a token for authentication used by Tencent Cloud to identify whether the current user can use TRTC services. You can generate a temporarily usable UserSig through the Auxiliary Tools in the console. For more information, see UserSig.
Note:
Development Environment: If you are in the local development and debugging stage, you can use the local GenerateTestUserSig.genTestSig function to generate UserSig. In this method, the SDKSecretKey is vulnerable to decompilation and reverse engineering. If your key is leaked, attackers can steal your Tencent Cloud traffic.
Production environment: If your project is to be released online, please use the server-generated UserSig method.
Step 5. Create a voice chat room
After the above log in to method call returns successfully, call the VoiceRoomKit method createRoom to create your voice chat live streaming room.
After the above log in to method call returns successfully, call the VoiceRoomKit method enterRoom, specify the room ID, and enter the Voice Chat Room Live Streaming.