tencent cloud

文档反馈

最后更新时间:2024-04-29 16:42:01
    本文将介绍如何用最短的时间完成 TUIRoomKit 组件的接入,跟随本文档,您将在一个小时的时间内完成如下几个关键步骤,并最终得到一个包含完备 UI 界面的音视频会议功能。

    环境准备

    最低兼容 Android 4.4(SDK API Level 19),建议使用 Android 5.0 (SDK API Level 21)及以上版本。
    Android Studio 3.5 及以上的版本(Gradle 3.5.4 及以上的版本)。
    Android 4.4 及以上的手机设备。

    步骤一:开通服务

    在使用 TUIRoomKit 发起会议前,您需要前往控制台开通 TUIRoomKit 专属的多人音视频互动服务,具体步骤请参见 开通服务

    步骤二:下载 TUIRoomKit 组件

    1. Github 中克隆/下载代码,然后拷贝Android目录下的timcommontuiroomkit子目录到您当前工程中的 app 同级目录中,如下图:
    
    
    

    步骤三:工程配置

    1. 工程根目录下找到setting.gradle(或settings.gradle.kts)文件,并在其中增加如下代码,它的作用是将tuiroomkit组件导入到您当前的项目中。
    Java
    Kotlin
    include ':timcommon'
    include ':tuiroomkit'
    include (":timcommon") include (":tuiroomkit")
    2. 在 app 目录下找到build.gradle(或build.gradle.kts)文件,并在其中增加如下代码,它的作用是声明当前app对新加入的tuiroomkit组件的依赖。
    Java
    Kotlin
    api project(':tuiroomkit')
    api(project(":tuiroomkit"))
    3. 由于我们在 SDK 内部使用了Java 的反射特性,需要将 SDK 中的部分类加入不混淆名单,因此需要您在 proguard-rules.pro 文件中添加如下代码:
    -keep class com.tencent.** { *; }

    步骤四:登录

    在您的项目中添加如下代码,它的作用是通过调用TUILogin中的相关接口完成组件的登录。这个步骤异常关键,因为只有在登录后才能正常使用 TUIRoomKit的各项功能,故请您耐心检查相关参数是否配置正确:
    Java
    Kotlin
    TUILogin.login(context,
    1400000001, // 请替换为步骤一取到的 SDKAppID
    "denny", // 请替换为您的 UserID
    "xxxxxxxxxxx", // 您可以在控制台中计算一个 UserSig 并填在这个位置
    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);
    }
    });
    TUILogin.login(this,
    1400000001, // 请替换为步骤一取到的 SDKAppID
    "denny", // 请替换为您的 UserID
    "xxxxxxxxxxx", // 您可以在控制台中计算一个 UserSig 并填在这个位置
    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);
    }
    })
    }
    参数说明 这里详细介绍一下 login 函数中所需要用到的几个关键参数:
    SDKAppID:在 开通服务 中的最后一步中获取。
    UserID:当前用户的 ID,字符串类型,只允许包含英文字母(a-z 和 A-Z)、数字(0-9)、连词符(-)和下划线(_)。
    UserSig:使用 开通服务 的第3步中获取的SDKSecretKeySDKAppIDUserID等信息进行加密,就可以得到UserSig,它是一个鉴权用的票据,用于腾讯云识别当前用户是否能够使用TRTC的服务。您可以通过控制台中的 辅助工具 生成一个临时可用的UserSig
    更多信息请参见 如何计算及使用 UserSig

    步骤五:发起您的第一次会议

    1. 新建 activity_conference.xml 文件,并添加界面布局:
    <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conference_container" android:layout_width="match_parent" android:layout_height="match_parent" />
    2. ConferenceMainFragment 是会议的主界面,只需调用 quickStartConference 发起快速会议,并在快速会议的回调 onConferenceStarted 中将 ConferenceMainFragment 添加到当前 Activity 中,即可发起快速会议。
    Java
    Kotlin
    public class ConferenceOwnerActivity extends AppCompatActivity {
    private static final String TAG = "ConferenceOwnerActivity";
    
    private ConferenceObserver mConferenceObserver;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    
    ConferenceMainFragment fragment = new ConferenceMainFragment();
    mConferenceObserver = new ConferenceObserver() {
    @Override
    public void onConferenceStarted(String conferenceId, ConferenceError error) {
    super.onConferenceStarted(conferenceId, error);
    if (error != ConferenceError.SUCCESS) {
    Log.e(TAG, "Error : " + error);
    return;
    }
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.conference_container, fragment);
    transaction.commitAllowingStateLoss();
    }
    };
    fragment.setConferenceObserver(mConferenceObserver);
    // Replace "123456" with the corresponding conference number
    fragment.quickStartConference("123456");
    }
    }
    class ConferenceOwnerActivity : AppCompatActivity() { private val tag: String = "ConferenceOwnerActivity" private var mConferenceObserver : ConferenceObserver? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_conference) var fragment = ConferenceMainFragment() mConferenceObserver = object: ConferenceObserver() { override fun onConferenceStarted(conferenceId: String?, error: ConferenceError?) { super.onConferenceStarted(conferenceId, error) if (error != ConferenceError.SUCCESS) { Log.e(tag, "Error : $error") return } val fragmentManager = supportFragmentManager val transaction = fragmentManager.beginTransaction() transaction.add(R.id.conference_container, fragment) transaction.commitAllowingStateLoss() } } fragment.setConferenceObserver(mConferenceObserver) // Replace "123456" with the corresponding conference number fragment.quickStartConference("123456") } }
    注意
    ConferenceOwnerActivity 必须继承 AppCompatActivity,否则界面将无法显示。

    步骤六:普通成员加入会议

    1. ConferenceMainFragment 是会议的主界面,只需调用 joinConference 加入会议,并在加入会议的回调 onConferenceJoined 中将 ConferenceMainFragment 添加到当前 Activity 中,即可参与当前会议。
    Java
    Kotlin
    public class ConferenceGeneralActivity extends AppCompatActivity {
    private static final String TAG = "ConferenceGeneralActivity";
    
    private ConferenceObserver mConferenceObserver;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    
    ConferenceMainFragment fragment = new ConferenceMainFragment();
    mConferenceObserver = new ConferenceObserver() {
    @Override
    public void onConferenceJoined(String conferenceId, ConferenceError error) {
    super.onConferenceJoined(conferenceId, error);
    if (error != ConferenceError.SUCCESS) {
    Log.e(TAG, "Error : " + error);
    return;
    }
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.conference_container, fragment);
    transaction.commitAllowingStateLoss();
    }
    };
    fragment.setConferenceObserver(mConferenceObserver);
    // Replace "123456" with the corresponding conference number
    fragment.joinConference("123456");
    }
    }
    class ConferenceGeneralActivity : AppCompatActivity() { private val tag: String = "ConferenceGeneralActivity" private var mConferenceObserver : ConferenceObserver? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_conference) var fragment = ConferenceMainFragment() mConferenceObserver = object: ConferenceObserver() { override fun onConferenceJoined(conferenceId: String?, error: ConferenceError?) { super.onConferenceJoined(conferenceId, error) if (error != ConferenceError.SUCCESS) { Log.e(tag, "Error : $error") return } val fragmentManager = supportFragmentManager val transaction = fragmentManager.beginTransaction() transaction.add(R.id.conference_container, fragment) transaction.commitAllowingStateLoss() } } fragment.setConferenceObserver(mConferenceObserver) // Replace "123456" with the corresponding conference number fragment.joinConference("123456789") } }
    注意
    ConferenceGeneralActivity 必须继承 AppCompatActivity,否则界面将无法显示。
    
    
    
    会议主界面
    
    
    
    用户列表

    常见问题

    如果您的接入和使用中遇到问题,请参见 常见问题

    交流与反馈

    您在接入或使用过程有任何疑问或者建议,欢迎联系:info_rtc@tencent.com 。
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持