tencent cloud

Feedback

Last updated: 2024-09-27 12:37:57
    This article will guide you through the process of quickly integrating the TUILiveKit component. By following this document, you will complete the following key steps within an hour and ultimately obtain a video or voice live streaming function with a complete UI interface.

    Environment Preparations

    Android 5.0 (SDK API level 21) or above.
    Android Studio 7.0 or above.
    Devices with Android 5.0 or above.
    If you have any questions during environment configuration or compilation and running, please refer to the FAQ.

    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 the jitpack repository URL 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" and android:allowBackup="false" to the application node to override the component's 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 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. Start live streaming

    After the above log in to method call returns successfully, call the VideoLiveKit's startLive method, specifying the room ID to start your live streaming page.
    Kotlin
    Java
    import com.trtc.uikit.livekit.VideoLiveKit
    
    VideoLiveKit.createInstance(applicationContext).startLive("roomId")
    import com.trtc.uikit.livekit.VideoLiveKit;
    
    VideoLiveKit.createInstance(getApplicationContext()).startLive("roomId");
    
    
    
    Video Live Preview Screen
    
    
    
    Live video streaming with pictures

    Step 6. Watch the live stream

    After the above log in to method call returns successfully, call the VideoLiveKit's joinLive method, specifying the room ID to start your live streaming page.
    Kotlin
    Java
    import com.trtc.uikit.livekit.VideoLiveKit
    
    VideoLiveKit.createInstance(applicationContext).joinLive("roomId")
    import com.trtc.uikit.livekit.VideoLiveKit;
    
    VideoLiveKit.createInstance(getApplicationContext()).joinLive("roomId");
    
    
    
    Video Live Room
    
    
    
    Video Live Room

    More features

    Room List

    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