Our broadcasters' streaming and viewers watching feature mainly depend on our core widget of the voice chat room (SeatGridView), which provides a rich array of APIs for managing voice chat rooms, such as opening and closing them, managing seats within the live room, like applying for a seat, inviting to a seat, moving seats, kicking users off the seat, and more.
After you've integrated the voice chat room UIKit through Quick Access, if there's a discrepancy between the UI style and your ideal UI style, you can use our core widgets to quickly build the main process of the voice chat room within half an hour. Then, add your own business UI views on top of it.
Environment Requirements
Android 5.0 (SDK API Level 21) or later.
Gradle v7.0 or later.
Mobile device on Android 5.0 or later.
For issues during environment configuration or compilation, please refer to FAQ.
1. Find the build.gradle.kts (or build.gradle) file under the app directory and add the following code to include the dependency for SeatGridView component:
api 'io.trtc.uikit:voice-room-core:latest.release'
2. 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.voiceroomcore.**{*;}
3. Find the AndroidManifest.xml file under the app directory and add tools:replace="android:allowBackup" and android:allowBackup="false" in the application node to override the settings within the component with your own settings.
// app/src/main/AndroidManifest.xml
<application
...
// Add the following configuration to override the configuration in the dependency SDK
android:allowBackup="false"
tools:replace="android:allowBackup">
Step 3. Log in
Add the following code to your project, which completes the login of TUI Components by calling the relevant interfaces in TUICore. This step is critical; you can only use the features provided by SeatGridView after successful login.
Kotlin
Java
// Log in
TUILogin.login(applicationContext,
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
object :TUICallback(){
override fun onSuccess(){
Log.i(TAG,"login success")
}
override fun onError(errorCode:Int, errorMessage:String){
Here we detail the key parameters required in the login function:
Parameter
Type
Description
SDKAppID
int
You have already obtained it in the last step of Step 1, so it will not be elaborated here.
UserID
String
The ID of the current user, in string format, only allows letters (a-z and A-Z), digits (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 4: Use core controls to implement the live streaming feature
Create core controls
Create core controls: You can load our core controls in your Activity through Java code or XML. The code example is as follows (XML method is similar):
kotlin
java
val seatGridView =SeatGridView(this)
SeatGridView seatGridView =newSeatGridView(this);
The anchor starts the live streaming room and the audience joins the live streaming room
Anchor starts the live streaming room: Start a live streaming room and enable local microphone capturing.
If you think our default UI does not meet your needs and you want to customize your seat view, you can quickly set up your seat layout in the following ways to fully customize your seat view UI.
kotlin
java
val adapter = object :VoiceRoomDefine.SeatViewAdapter{
override fun createSeatView(seatGridView:SeatGridView, seatInfo:TUIRoomDefine.SeatInfo):View{