tencent cloud

Feedback

Last updated: 2024-09-24 17:23:06
    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):
    settings.gradle.kts
    settings.gradle
    dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral()
    // Add jitpack repository address maven { url = uri("https://jitpack.io") } } }
    dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral()
    
    // Add the jitpack repository URL maven { url 'https://jitpack.io' } } }
    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")
    include ':tuilivekit'
    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"))
    api project(':tuilivekit')
    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.** { *; }
    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
    android:allowBackup="false" tools:replace="android:allowBackup">

    Step 4. Log in

    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
    new TUICallback() {
    @Override
    public void onSuccess() {
    Log.i(TAG, "login success");
    }
    
    @Override
    public void onError(int errorCode, String errorMessage) {
    Log.e(TAG, "login failed, errorCode: " + errorCode + " msg:" + errorMessage);
    }
    });
    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.
    Kotlin
    Java
    import com.trtc.uikit.livekit.VoiceRoomKit;
    
    VoiceRoomKit.createInstance(applicationContext).createRoom("roomId", VoiceRoomDefine.CreateRoomParams())
    import com.trtc.uikit.livekit.VoiceRoomKit;
    
    VoiceRoomKit.createInstance(getApplicationContext()).createRoom("roomId", new VoiceRoomDefine.CreateRoomParams());
    Voice chat room preview screen
    Voice chat room in-room screen
    
    
    
    
    
    

    Step 6: Join the voice chat 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.
    Kotlin
    Java
    import com.trtc.uikit.livekit.VoiceRoomKit;
    
    VoiceRoomKit.createInstance(applicationContext).enterRoom("roomId")
    import com.trtc.uikit.livekit.VoiceRoomKit;
    
    VoiceRoomKit.createInstance(getApplicationContext()).enterRoom("roomId");
    Voice Chat Room
    Voice Chat Room
    
    
    
    
    
    

    More features

    Room List
    Barrage
    Gift

    Q&A

    If you encounter problems with access and use, see Q&A.

    Suggestions and Feedback

    If you have any suggestions or feedback, please contact info_rtc@tencent.com.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support