本文将指导您如何在较短时间内接入
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 组件
1. 在 Github 中克隆/下载代码,然后拷贝
Android
目录下的timcommon
、 tuiroomkit
子目录到您当前工程中的 app 同级目录中,如下图:
步骤三:工程配置
1. 工程根目录下找到
setting.gradle
文件,并在其中增加如下代码,它的作用是将tuiroomkit
组件导入到您当前的项目中。include ':timcommon'include ':tuiroomkit'
2. 在 app 目录下找到
build.gradle
文件,并在其中增加如下代码,它的作用是声明当前app
对新加入的tuiroomkit
组件的依赖。api project(':tuiroomkit')
3. 由于我们在 SDK 内部使用了Java 的反射特性,需要将 SDK 中的部分类加入不混淆名单,因此需要您在 proguard-rules.pro 文件中添加如下代码:
-keep class com.tencent.** { *; }
步骤四:登录
在您的项目中添加如下代码,它的作用是通过调用
TUILogin
中的相关接口完成组件的登录。这个步骤异常关键,因为只有在登录后才能正常使用 TUIRoomKit
的各项功能,故请您耐心检查相关参数是否配置正确:TUILogin.login(context,1400000001, // 请替换为开通服务取到的 SDKAppID"998", // 请替换为您的 UserID"xxxxxxxxxx", // 您可以在控制台中计算一个 UserSig 并填在这个位置callback); // 登录是否成功的回调
参数说明
这里详细介绍一下
login
函数中所需要用到的几个关键参数:SDKAppID:在 开通服务 中的最后一步中获取。
UserID:当前用户的 ID,字符串类型,只允许包含英文字母(a-z 和 A-Z)、数字(0-9)、连词符(-)和下划线(_)。
UserSig:使用 开通服务 的第3步中获取的
SDKSecretKey
对SDKAppID
、UserID
等信息进行加密,就可以得到UserSig
,它是一个鉴权用的票据,用于腾讯云识别当前用户是否能够使用TRTC
的服务。您可以通过控制台中的 辅助工具 生成一个临时可用的UserSig
。更多信息请参见 如何计算及使用 UserSig。
步骤五:发起您的第一次会议
1. 新建 activity_conference_owner.xml 文件,并添加界面布局:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conference_owner_container" android:layout_width="match_parent" android:layout_height="match_parent" />
2. ConferenceMainFragment 是会议的主界面,只需调用 quickStartConference 发起快速会议,并在快速会议的回调 onConferenceStarted 中将 ConferenceMainFragment 添加到当前 Activity 中,即可发起快速会议。
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_owner); 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_owner_container, fragment); transaction.commitAllowingStateLoss(); } };fragment.setConferenceObserver(mConferenceObserver);//"123456" 替换为对应的会议号 fragment.quickStartConference("123456");} }
注意
ConferenceOwnerActivity 必须继承 AppCompatActivity,否则界面将无法显示。
步骤六:普通成员加入会议
1. 新建 activity_conference_general.xml 文件,并添加界面布局:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/conference_general_container" android:layout_width="match_parent" android:layout_height="match_parent" />
2. ConferenceMainFragment 是会议的主界面,只需调用 joinConference 加入会议,并在加入会议的回调 onConferenceJoined 中将 ConferenceMainFragment 添加到当前 Activity 中,即可参与当前会议。
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_general); 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_general_container, fragment); transaction.commitAllowingStateLoss(); } }; fragment.setConferenceObserver(mConferenceObserver);//"123456" 替换为对应的会议号 fragment.joinConference("123456");} }
注意
ConferenceGeneralActivity 必须继承 AppCompatActivity,否则界面将无法显示。
成员会议主界面 | 成员用户列表 |
常见问题
交流与反馈