@tencentcloud/sdk-mcp 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +1 -1
  2. package/resource/doc/livekit/live/android/live-audience-list.md +335 -0
  3. package/resource/doc/livekit/live/android/live-audio-effect.md +384 -0
  4. package/resource/doc/livekit/live/android/live-barrage.md +569 -0
  5. package/resource/doc/livekit/live/android/live-base-beauty.md +265 -0
  6. package/resource/doc/livekit/live/android/live-co-guest-interaction.md +600 -0
  7. package/resource/doc/livekit/live/android/live-gift.md +833 -0
  8. package/resource/doc/livekit/live/android/live-host-interaction.md +810 -0
  9. package/resource/doc/livekit/live/android/live-integration.md +883 -0
  10. package/resource/doc/livekit/live/android/live-live-list.md +657 -0
  11. package/resource/doc/livekit/live/android/workflow.md +189 -0
  12. package/tools/common/record-prompt.js +2 -2
  13. package/tools/common/record-prompt.js.map +1 -1
  14. package/tools/definitions/get_native_live_extra_features_def.js +109 -0
  15. package/tools/definitions/get_native_live_extra_features_def.js.map +1 -0
  16. package/tools/definitions/get_native_live_interaction_def.js +115 -0
  17. package/tools/definitions/get_native_live_interaction_def.js.map +1 -0
  18. package/tools/definitions/get_native_live_uikit_integration_def.js +50 -0
  19. package/tools/definitions/get_native_live_uikit_integration_def.js.map +1 -0
  20. package/tools/definitions/record_prompt_def.js +1 -1
  21. package/tools/definitions/record_prompt_def.js.map +1 -1
  22. package/tools/index.js +6 -0
  23. package/tools/index.js.map +1 -1
  24. package/tools/live/get-native-live-uikit-integration.js +101 -0
  25. package/tools/live/get-native-live-uikit-integration.js.map +1 -0
  26. package/tools/live/get-web-live-component-detail.js +1 -1
  27. package/tools/live/get-web-live-component-detail.js.map +1 -1
  28. package/tools/live/get-web-live-state-detail.js +1 -1
  29. package/tools/live/get-web-live-state-detail.js.map +1 -1
  30. package/tools/live/get-web-live-uikit-integration.js +6 -6
  31. package/tools/live/get-web-live-uikit-integration.js.map +1 -1
  32. package/tools/live/get_native_live_extra_features.js +105 -0
  33. package/tools/live/get_native_live_extra_features.js.map +1 -0
  34. package/tools/live/get_native_live_interaction.js +101 -0
  35. package/tools/live/get_native_live_interaction.js.map +1 -0
  36. package/utils/generate-structured-result.js +1 -1
  37. package/utils/report-cls-client.js +1 -1
  38. package/utils/report-es-client.js +1 -1
  39. /package/resource/doc/livekit/{vue → live/vue}/components/barrage.md +0 -0
  40. /package/resource/doc/livekit/{vue → live/vue}/components/co-guest-panel.md +0 -0
  41. /package/resource/doc/livekit/{vue → live/vue}/components/live-audience-list.md +0 -0
  42. /package/resource/doc/livekit/{vue → live/vue}/components/live-scene-panel.md +0 -0
  43. /package/resource/doc/livekit/{vue → live/vue}/components/live-view.md +0 -0
  44. /package/resource/doc/livekit/{vue → live/vue}/components/stream-mixer.md +0 -0
  45. /package/resource/doc/livekit/{vue → live/vue}/faq.md +0 -0
  46. /package/resource/doc/livekit/{vue → live/vue}/live-list-integration.md +0 -0
  47. /package/resource/doc/livekit/{vue → live/vue}/live-player-desk-integration.md +0 -0
  48. /package/resource/doc/livekit/{vue → live/vue}/live-player-h5-integration.md +0 -0
  49. /package/resource/doc/livekit/{vue → live/vue}/live-pusher-integration.md +0 -0
  50. /package/resource/doc/livekit/{vue → live/vue}/states/live-state.md +0 -0
  51. /package/resource/doc/livekit/{vue → live/vue}/workflow.md +0 -0
@@ -0,0 +1,883 @@
1
+ 本文档将帮助您使用 **AtomicXCore SDK**的核心组件 [LiveCoreView](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.view/-live-core-view/index.html),快速构建一个包含主播开播和观众观看功能的基础直播 App。
2
+
3
+ ### **核心功能**
4
+
5
+ **LiveCoreView** 是一个专为直播场景设计的轻量级 `View` 组件,是您构建直播场景的核心,它封装了所有复杂的底层直播技术(如推拉流、连麦、音视频渲染)。您可以将 LiveCoreView 作为直播画面的"画布",专注于上层 UI 与交互的开发。
6
+
7
+ 通过下方的视图层级示意图,您可以直观了解 **LiveCoreView** 在直播界面中的位置和作用:
8
+
9
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100032603567/8854e196ae4711f096c2525400454e06.png)
10
+
11
+
12
+ ## 准备工作
13
+
14
+ ### 步骤1:开通服务
15
+
16
+ 请参见 [开通服务](https://write.woa.com/document/141302177829593088),获取体验版或付费版 SDK。
17
+
18
+ ### 步骤2:在当前项目中导入 AtomicXCore
19
+
20
+ **安装组件**:请在您的 **build.gradle** 文件中添加 `implementation 'com.tencent.atomicx:atomicxcore:latest'` 依赖,然后执行 **Gradle Sync**。
21
+ ``` gradle
22
+ dependencies {
23
+ implementation 'io.trtc.uikit:atomicx-core:latest.release'
24
+ api "io.trtc.uikit:rtc_room_engine:3.4.0.1306"
25
+ api "io.trtc.uikit:atomicx-core:3.4.0.1307"
26
+ api "com.tencent.liteav:LiteAVSDK_Professional:12.8.0.19279"
27
+ api "com.tencent.imsdk:imsdk-plus:8.7.7201"
28
+ // 其他依赖...
29
+ }
30
+ ```
31
+
32
+ ### 步骤3:实现登录逻辑
33
+
34
+ 在您的项目中调用 `LoginStore.shared.login`完成登录,**这是使用 **`AtomicXCore`** 所有功能的关键前提**。
35
+
36
+ > **重要:**
37
+ >
38
+
39
+ > 推荐在您 App 自身的用户账户登录成功后,再调用 LoginStore.shared.login,以确保登录业务逻辑的清晰和一致。
40
+ >
41
+
42
+ ``` java
43
+ import android.os.Bundle
44
+ import androidx.appcompat.app.AppCompatActivity
45
+ import io.trtc.tuikit.atomicxcore.api.login.LoginStore
46
+ import io.trtc.tuikit.atomicxcore.api.CompletionHandler
47
+ import android.util.Log
48
+
49
+ class MainActivity : AppCompatActivity() {
50
+ override fun onCreate(savedInstanceState: Bundle?) {
51
+ super.onCreate(savedInstanceState)
52
+
53
+ LoginStore.shared.login(
54
+ this, // context
55
+ 1400000001, // 替换为您的 SDKAppID
56
+ "test_001", // 替换为您的 UserID
57
+ "xxxxxxxxxxx", // 替换为您的 UserSig
58
+ object : CompletionHandler {
59
+ override fun onSuccess() {
60
+ // 登录成功处理
61
+ Log.d("Login", "login success");
62
+ }
63
+
64
+ override fun onFailure(code: Int, desc: String) {
65
+ // 登录失败处理
66
+ Log.e("Login", "login failed, code: $code, error: $desc");
67
+ }
68
+ }
69
+ )
70
+ }
71
+ }
72
+ ```
73
+
74
+ **登录接口参数说明:**
75
+ <table>
76
+ <tr>
77
+ <td rowspan="1" colSpan="1" >参数</td>
78
+
79
+ <td rowspan="1" colSpan="1" >类型</td>
80
+
81
+ <td rowspan="1" colSpan="1" >说明</td>
82
+ </tr>
83
+
84
+ <tr>
85
+ <td rowspan="1" colSpan="1" >sdkAppId</td>
86
+
87
+ <td rowspan="1" colSpan="1" >Int</td>
88
+
89
+ <td rowspan="1" colSpan="1" >从 [控制台](https://console.cloud.tencent.com/trtc) 获取,通常是以 `140` 或 `160` 开头的 10 位整数。</td>
90
+ </tr>
91
+
92
+ <tr>
93
+ <td rowspan="1" colSpan="1" >userID</td>
94
+
95
+ <td rowspan="1" colSpan="1" >String</td>
96
+
97
+ <td rowspan="1" colSpan="1" >当前用户的唯一 ID,仅包含英文字母、数字、连字符和下划线。为避免多端登录冲突,**请勿使用**`1`、`123`**等简单 ID**。</td>
98
+ </tr>
99
+
100
+ <tr>
101
+ <td rowspan="1" colSpan="1" >userSig</td>
102
+
103
+ <td rowspan="1" colSpan="1" >String</td>
104
+
105
+ <td rowspan="1" colSpan="1" >用于腾讯云鉴权的票据。请注意:<br>- 开发环境:您可以采用本地 `GenerateTestUserSig.genTestSig` 函数生成 userSig 或者 通过 [UserSig 辅助工具](https://console.cloud.tencent.com/im/tool-usersig) 生成临时的 UserSig。<br>- 生产环境:为了防止密钥泄露,请务必采用服务端生成 UserSig 的方式。详细信息请参考 [服务端生成 UserSig](https://cloud.tencent.com/document/product/647/17275)。<br>更多信息请参见 [如何计算及使用 UserSig](https://cloud.tencent.com/document/product/647/17275)。</td>
106
+ </tr>
107
+ </table>
108
+
109
+
110
+ ## 搭建基础直播间
111
+
112
+ ### 步骤1:实现主播视频开播
113
+
114
+ 主播开播流程如下,您只需执行以下几步操作,即可快速搭建主播视频直播。
115
+
116
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100032603567/e302f6e5ae4711f0b08552540044a08e.png)
117
+
118
+
119
+ > **提示:**
120
+ >
121
+
122
+ > 主播开播推流的业务代码,您也可以参考 TUILiveKit 开源项目中的 [VideoLiveAnchorActivity.kt](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/live/tuilivekit/src/main/java/com/trtc/uikit/livekit/livestream/VideoLiveAnchorActivity.kt) 文件来了解完整的实现逻辑。
123
+ >
124
+
125
+ 1. **初始化主播推流的视图**
126
+
127
+
128
+ 在您的主播 Activity 中,创建一个 `LiveCoreView` 实例,并将 `viewType` 指定为 `PUSH_VIEW`(推流视图)。
129
+
130
+ ``` java
131
+ import io.trtc.tuikit.atomicxcore.api.view.CoreViewType
132
+ import io.trtc.tuikit.atomicxcore.api.view.LiveCoreView
133
+ import android.os.Bundle
134
+ import androidx.appcompat.app.AppCompatActivity
135
+ import androidx.constraintlayout.widget.ConstraintLayout
136
+
137
+ // YourAnchorActivity 代表您的主播开播Activity
138
+ class YourAnchorActivity : AppCompatActivity() {
139
+
140
+ // 1. 将 LiveCoreView 作为您Activity的一个属性
141
+ private lateinit var coreView: LiveCoreView
142
+
143
+ override fun onCreate(savedInstanceState: Bundle?) {
144
+ super.onCreate(savedInstanceState)
145
+
146
+ // 2. 初始化视图
147
+ coreView = LiveCoreView(this, viewType = CoreViewType.PUSH_VIEW)
148
+ coreView.setLiveID("test_live_001")
149
+
150
+ // 布局 UI
151
+ setupUI()
152
+ }
153
+
154
+ private fun setupUI() {
155
+ setContentView(R.layout.activity_anchor)
156
+
157
+ // 3. 将主播推流页面加载到您的视图上
158
+ val container = findViewById<ConstraintLayout>(R.id.container)
159
+ container.addView(coreView)
160
+
161
+ // 设置布局参数
162
+ val params = ConstraintLayout.LayoutParams(
163
+ ConstraintLayout.LayoutParams.MATCH_PARENT,
164
+ ConstraintLayout.LayoutParams.MATCH_PARENT
165
+ )
166
+ params.topMargin = 36
167
+ params.bottomMargin = 96
168
+ coreView.layoutParams = params
169
+ }
170
+ }
171
+
172
+ ```
173
+ 2. **打开摄像头和麦克风**
174
+
175
+
176
+ 通过调用 **DeviceStore** 的 `openLocalCamera、openLocalMicrophone` 接口打开摄像头和麦克风,**您无需做额外操作,LiveCoreView 会自动预览当前摄像头的视频流**,示例代码如下:
177
+
178
+ ``` java
179
+ import androidx.appcompat.app.AppCompatActivity
180
+ import android.os.Bundle
181
+ import io.trtc.tuikit.atomicxcore.api.device.DeviceStore
182
+
183
+ class YourAnchorActivity : AppCompatActivity() {
184
+ // ... 其他代码 ...
185
+
186
+ override fun onCreate(savedInstanceState: Bundle?) {
187
+ super.onCreate(savedInstanceState)
188
+ // 布局 UI
189
+ setupUI()
190
+ // 打开设备
191
+ openDevices()
192
+ }
193
+
194
+ private fun openDevices() {
195
+ // 1. 打开前置摄像头
196
+ DeviceStore.shared().openLocalCamera(true, completion = null)
197
+ // 2. 打开麦克风
198
+ DeviceStore.shared().openLocalMicrophone(completion = null)
199
+ }
200
+ }
201
+ ```
202
+ 3. **开始直播**
203
+
204
+
205
+ 通过调用 **LiveListStore** 的 `createLive` 接口开始视频直播,完整示例代码如下:
206
+
207
+ ``` java
208
+ import android.util.Log
209
+ import androidx.appcompat.app.AppCompatActivity
210
+ import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
211
+ import io.trtc.tuikit.atomicxcore.api.live.LiveInfoCompletionHandler
212
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
213
+
214
+ class YourAnchorActivity : AppCompatActivity() {
215
+
216
+ // ... 其他代码 ...
217
+
218
+ // 调用开播接口开始直播
219
+ private fun startLive() {
220
+ val liveInfo = LiveInfo().apply {
221
+ // 1. 设置直播的房间 id
222
+ liveID = "test_live_001"
223
+ // 2. 设置直播的房间名称
224
+ liveName = "test 直播"
225
+ // 3. 配置布局模板,默认:600 动态宫格布局
226
+ seatLayoutTemplateID = 600
227
+ // 4. 配置主播始终在麦位上
228
+ keepOwnerOnSeat = true
229
+ }
230
+ // 5. 调用 LiveListStore.shared().createLive 开始直播
231
+ LiveListStore.shared().createLive(liveInfo, object: LiveInfoCompletionHandler {
232
+ override fun onFailure(code: Int, desc: String) {
233
+ Log.e("Live", "Response startLive onError: $desc")
234
+ }
235
+
236
+ override fun onSuccess(liveInfo: LiveInfo) {
237
+ Log.d("Live", "Response startLive onSuccess")
238
+ }
239
+ })
240
+ }
241
+ }
242
+ ```
243
+
244
+ `LiveInfo`** 参数说明**
245
+
246
+ <table>
247
+ <tr>
248
+ <td rowspan="1" colSpan="1" >**参数名**</td>
249
+
250
+ <td rowspan="1" colSpan="1" >**类型**</td>
251
+
252
+ <td rowspan="1" colSpan="1" >**属性**</td>
253
+
254
+ <td rowspan="1" colSpan="1" >**描述**</td>
255
+ </tr>
256
+
257
+ <tr>
258
+ <td rowspan="1" colSpan="1" >`liveID`</td>
259
+
260
+ <td rowspan="1" colSpan="1" >`String`</td>
261
+
262
+ <td rowspan="1" colSpan="1" >必填</td>
263
+
264
+ <td rowspan="1" colSpan="1" >直播间的唯一标识符。</td>
265
+ </tr>
266
+
267
+ <tr>
268
+ <td rowspan="1" colSpan="1" >`liveName`</td>
269
+
270
+ <td rowspan="1" colSpan="1" >`String`</td>
271
+
272
+ <td rowspan="1" colSpan="1" >选填</td>
273
+
274
+ <td rowspan="1" colSpan="1" >直播间的标题。</td>
275
+ </tr>
276
+
277
+ <tr>
278
+ <td rowspan="1" colSpan="1" >`notice`</td>
279
+
280
+ <td rowspan="1" colSpan="1" >`String`</td>
281
+
282
+ <td rowspan="1" colSpan="1" >选填</td>
283
+
284
+ <td rowspan="1" colSpan="1" >直播间的公告信息。</td>
285
+ </tr>
286
+
287
+ <tr>
288
+ <td rowspan="1" colSpan="1" >`isMessageDisable`</td>
289
+
290
+ <td rowspan="1" colSpan="1" >`Boolean`</td>
291
+
292
+ <td rowspan="1" colSpan="1" >选填</td>
293
+
294
+ <td rowspan="1" colSpan="1" >是否禁言(`true`:是,`false`:否)。</td>
295
+ </tr>
296
+
297
+ <tr>
298
+ <td rowspan="1" colSpan="1" >`isPublicVisible`</td>
299
+
300
+ <td rowspan="1" colSpan="1" >`Boolean`</td>
301
+
302
+ <td rowspan="1" colSpan="1" >选填</td>
303
+
304
+ <td rowspan="1" colSpan="1" >是否公开可见(`true`:是,`false`:否)。</td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td rowspan="1" colSpan="1" >`isSeatEnabled`</td>
309
+
310
+ <td rowspan="1" colSpan="1" >`Boolean`</td>
311
+
312
+ <td rowspan="1" colSpan="1" >选填</td>
313
+
314
+ <td rowspan="1" colSpan="1" >是否启用麦位功能(`true`:是,`false`:否)。</td>
315
+ </tr>
316
+
317
+ <tr>
318
+ <td rowspan="1" colSpan="1" >`keepOwnerOnSeat`</td>
319
+
320
+ <td rowspan="1" colSpan="1" >`Boolean`</td>
321
+
322
+ <td rowspan="1" colSpan="1" >选填</td>
323
+
324
+ <td rowspan="1" colSpan="1" >是否保持房主在麦位上。</td>
325
+ </tr>
326
+
327
+ <tr>
328
+ <td rowspan="1" colSpan="1" >`maxSeatCount`</td>
329
+
330
+ <td rowspan="1" colSpan="1" >`Int`</td>
331
+
332
+ <td rowspan="1" colSpan="1" >必填</td>
333
+
334
+ <td rowspan="1" colSpan="1" >最大麦位数量。</td>
335
+ </tr>
336
+
337
+ <tr>
338
+ <td rowspan="1" colSpan="1" >`seatMode`</td>
339
+
340
+ <td rowspan="1" colSpan="1" >[TakeSeatMode](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-take-seat-mode/index.html)</td>
341
+
342
+ <td rowspan="1" colSpan="1" >选填</td>
343
+
344
+ <td rowspan="1" colSpan="1" >上麦模式(`FREE`:自由上麦,`APPLY`:申请上麦)。</td>
345
+ </tr>
346
+
347
+ <tr>
348
+ <td rowspan="1" colSpan="1" >`seatLayoutTemplateID`</td>
349
+
350
+ <td rowspan="1" colSpan="1" >`Int`</td>
351
+
352
+ <td rowspan="1" colSpan="1" >必填</td>
353
+
354
+ <td rowspan="1" colSpan="1" >麦位布局模板 `ID`。</td>
355
+ </tr>
356
+
357
+ <tr>
358
+ <td rowspan="1" colSpan="1" >`coverURL`</td>
359
+
360
+ <td rowspan="1" colSpan="1" >`String`</td>
361
+
362
+ <td rowspan="1" colSpan="1" >选填</td>
363
+
364
+ <td rowspan="1" colSpan="1" >直播间的封面图片地址。</td>
365
+ </tr>
366
+
367
+ <tr>
368
+ <td rowspan="1" colSpan="1" >`backgroundURL`</td>
369
+
370
+ <td rowspan="1" colSpan="1" >`String`</td>
371
+
372
+ <td rowspan="1" colSpan="1" >选填</td>
373
+
374
+ <td rowspan="1" colSpan="1" >直播间的背景图片地址。</td>
375
+ </tr>
376
+
377
+ <tr>
378
+ <td rowspan="1" colSpan="1" >`categoryList`</td>
379
+
380
+ <td rowspan="1" colSpan="1" >`List<Int>`</td>
381
+
382
+ <td rowspan="1" colSpan="1" >选填</td>
383
+
384
+ <td rowspan="1" colSpan="1" >直播间的分类标签列表。</td>
385
+ </tr>
386
+
387
+ <tr>
388
+ <td rowspan="4" colSpan="1" >`activityStatus`</td>
389
+
390
+ <td rowspan="4" colSpan="1" >`Int`</td>
391
+
392
+ <td rowspan="4" colSpan="1" >选填</td>
393
+
394
+ <td rowspan="4" colSpan="1" >直播活动状态。</td>
395
+ </tr>
396
+
397
+ <tr></tr>
398
+
399
+ <tr></tr>
400
+
401
+ <tr></tr>
402
+
403
+ <tr>
404
+ <td rowspan="2" colSpan="1" >`isGiftEnabled`</td>
405
+
406
+ <td rowspan="2" colSpan="1" >`Boolean`</td>
407
+
408
+ <td rowspan="2" colSpan="1" >选填</td>
409
+
410
+ <td rowspan="2" colSpan="1" >是否启用礼物功能(`true`:是,`false`:否)。</td>
411
+ </tr>
412
+
413
+ <tr></tr>
414
+ </table>
415
+
416
+ 4. **结束直播**
417
+
418
+
419
+ 直播结束后,主播可以调用 **LiveListStore** 的 `endLive` 接口结束直播。SDK 会处理停止推流和销毁房间的逻辑。
420
+
421
+ ``` java
422
+ import android.util.Log
423
+ import androidx.appcompat.app.AppCompatActivity
424
+ import com.tencent.cloud.tuikit.engine.extension.TUILiveListManager
425
+ import io.trtc.tuikit.atomicxcore.api.device.DeviceStore
426
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
427
+ import io.trtc.tuikit.atomicxcore.api.live.StopLiveCompletionHandler
428
+
429
+ class YourAnchorActivity : AppCompatActivity() {
430
+
431
+ // ... 其他代码 ...
432
+
433
+ // 结束直播
434
+ private fun stopLive() {
435
+ LiveListStore.shared().endLive(object : StopLiveCompletionHandler {
436
+ override fun onSuccess(statisticsData: TUILiveListManager.LiveStatisticsData) {
437
+ Log.d("Live", "endLive success, duration: ${statisticsData.liveDuration}, totalViewers: ${statisticsData.totalViewers}")
438
+ }
439
+
440
+ override fun onFailure(code: Int, desc: String) {
441
+ Log.e("Live", "endLive error: $desc")
442
+ }
443
+ })
444
+ }
445
+
446
+ // 确保在 Activity 销毁时也调用结束直播
447
+ override fun onDestroy() {
448
+ super.onDestroy()
449
+ stopLive()
450
+ // 关闭本地设备
451
+ DeviceStore.shared().closeLocalCamera()
452
+ DeviceStore.shared().closeLocalMicrophone()
453
+ Log.d("Live", "YourAnchorActivity onDestroy")
454
+ }
455
+ }
456
+ ```
457
+
458
+ ### 步骤2:实现观众进房观看
459
+
460
+ 观众观看流程如下,通过简单几步操作,即可实现观众观看直播。
461
+
462
+ ![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100032603567/14058edaae4811f08bcc5254007c27c5.png)
463
+
464
+
465
+ > **提示:**
466
+ >
467
+
468
+ > 观众进房拉流的业务代码,您也可以参考 TUILiveKit 开源项目中的 [VideoLiveAudienceActivity.kt](https://github.com/Tencent-RTC/TUIKit_Android/blob/main/live/tuilivekit/src/main/java/com/trtc/uikit/livekit/livestream/VideoLiveAudienceActivity.kt) 文件来了解完整的实现逻辑。
469
+ >
470
+
471
+ 1. **添加观众拉流页面**
472
+
473
+
474
+ 在您的观众 Activity 中,创建 `LiveCoreView` 实例,并将 `viewType` 指定为`PLAY_VIEW`(拉流视图)。
475
+
476
+ ``` java
477
+ import io.trtc.tuikit.atomicxcore.api.view.CoreViewType
478
+ import io.trtc.tuikit.atomicxcore.api.view.LiveCoreView
479
+ import android.os.Bundle
480
+ import androidx.appcompat.app.AppCompatActivity
481
+ import androidx.constraintlayout.widget.ConstraintLayout
482
+
483
+ // YourAudienceActivity 代表您的观众观看Activity
484
+ class YourAudienceActivity : AppCompatActivity() {
485
+
486
+ // 1. 初始化观众拉流页面
487
+ private lateinit var coreView: LiveCoreView
488
+
489
+ override fun onCreate(savedInstanceState: Bundle?) {
490
+ super.onCreate(savedInstanceState)
491
+
492
+ // 2. 初始化视图
493
+ coreView = LiveCoreView(this, viewType = CoreViewType.PLAY_VIEW)
494
+ coreView.setLiveId("test_live_001")
495
+
496
+ // UI 布局
497
+ setupUI()
498
+ }
499
+
500
+ private fun setupUI() {
501
+ setContentView(R.layout.activity_audience)
502
+
503
+ // 3. 将观众拉流页面加载到您的视图上
504
+ val container = findViewById<ConstraintLayout>(R.id.container)
505
+ container.addView(coreView)
506
+
507
+ // 设置布局参数
508
+ val params = ConstraintLayout.LayoutParams(
509
+ ConstraintLayout.LayoutParams.MATCH_PARENT,
510
+ ConstraintLayout.LayoutParams.MATCH_PARENT
511
+ )
512
+ params.topMargin = 36
513
+ params.bottomMargin = 96
514
+ coreView.layoutParams = params
515
+ }
516
+ }
517
+ ```
518
+ 2. **进入直播间观看**
519
+
520
+
521
+ 通过调用 **LiveListStore** 的 `joinLive` 接口加入直播,**您无需做额外操作,LiveCoreView 会自动播放当前房间的视频流**,完整示例代码如下:
522
+
523
+ ``` java
524
+ import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
525
+ import io.trtc.tuikit.atomicxcore.api.live.LiveInfoCompletionHandler
526
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
527
+ import android.os.Bundle
528
+ import androidx.appcompat.app.AppCompatActivity
529
+ import android.util.Log
530
+
531
+ // YourAudienceActivity 代表您的观众观看Activity
532
+ class YourAudienceActivity : AppCompatActivity() {
533
+
534
+ // ... 其他代码 ...
535
+
536
+ override fun onCreate(savedInstanceState: Bundle?) {
537
+ super.onCreate(savedInstanceState)
538
+ setupUI()
539
+ // 1. 调用 LiveListStore.shared().joinLive 进入直播间
540
+ // - liveID: 与主播开播同样的 liveID
541
+ LiveListStore.shared().joinLive(liveID, object : LiveInfoCompletionHandler {
542
+ override fun onFailure(code: Int, desc: String) {
543
+ Log.e("Live", "joinLive error: $desc")
544
+ }
545
+
546
+ override fun onSuccess(liveInfo: LiveInfo) {
547
+ Log.d("Live", "joinLive success")
548
+ }
549
+ })
550
+ }
551
+ }
552
+ ```
553
+ 3. **退出直播**
554
+
555
+
556
+ 观众退出直播间时,需要调用 **LiveListStore** 的 `leaveLive` 接口退出直播。SDK 会自动停止拉流并退出房间。
557
+
558
+ ``` java
559
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
560
+ import io.trtc.tuikit.atomicxcore.api.CompletionHandler
561
+ import androidx.appcompat.app.AppCompatActivity
562
+ import android.util.Log
563
+
564
+ // YourAudienceActivity 代表您的观众观看Activity
565
+ class YourAudienceActivity : AppCompatActivity() {
566
+
567
+ // ... 其他代码 ...
568
+
569
+ // 退出直播
570
+ private fun leaveLive() {
571
+ LiveListStore.shared().leaveLive(object : CompletionHandler {
572
+ override fun onSuccess() {
573
+ Log.d("Live", "leaveLive success")
574
+ }
575
+
576
+ override fun onFailure(code: Int, desc: String) {
577
+ Log.e("Live", "leaveLive error: $desc")
578
+ }
579
+ })
580
+ }
581
+
582
+ // 确保在 Activity 销毁时也调用退出直播
583
+ override fun onDestroy() {
584
+ super.onDestroy()
585
+ leaveLive()
586
+ Log.d("Live", "YourAudienceActivity onDestroy")
587
+ }
588
+ }
589
+ ```
590
+
591
+ ### 步骤3:监听直播事件
592
+
593
+ 在观众加入直播间后,您还需要处理一些房间内的“被动”事件。例如主播主动结束了直播,或者观众因为违规等原因被踢出房间。如果不监听这些事件,观众端 UI 可能会停留在黑屏页面,影响用户体验。
594
+
595
+ 您可以通过实现 `LiveListListener` 监听器,并将其注册到 `LiveListStore` 来实现事件监听。
596
+ ``` java
597
+ import io.trtc.tuikit.atomicxcore.api.live.LiveEndedReason
598
+ import io.trtc.tuikit.atomicxcore.api.live.LiveKickedOutReason
599
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListListener
600
+ import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
601
+ import android.os.Bundle
602
+ import androidx.appcompat.app.AppCompatActivity
603
+ import android.util.Log
604
+
605
+ // YourAudienceActivity 代表您的观众观看Activity
606
+ class YourAudienceActivity : AppCompatActivity() {
607
+
608
+ // ... (coreView, liveId, setupUI, joinLive, leaveLive 等代码) ...
609
+
610
+ // 2. 定义一个 LiveListListener 实例
611
+ private val liveListListener = object : LiveListListener() {
612
+ override fun onLiveEnded(liveID: String, reason: LiveEndedReason, message: String) {
613
+ // 监听到直播结束
614
+ Log.d("Live", "Live ended. liveID: $liveID, reason: $reason, message: $message")
615
+ // 在此处处理退出直播间的逻辑,例如关闭当前 Activity
616
+ // finish()
617
+ }
618
+
619
+ override fun onKickedOutOfLive(liveID: String, reason: LiveKickedOutReason, message: String) {
620
+ // 监听到被踢出直播
621
+ Log.d("Live", "Kicked out of live. liveID: $liveID, reason: $reason, message: $message")
622
+ // 在此处处理退出直播间的逻辑
623
+ // finish()
624
+ }
625
+ }
626
+
627
+ override fun onCreate(savedInstanceState: Bundle?) {
628
+ super.onCreate(savedInstanceState)
629
+ setupUI()
630
+
631
+ // 3. 注册监听器
632
+ LiveListStore.shared().addLiveListListener(liveListListener)
633
+
634
+ // 4. 进入直播间
635
+ joinLive()
636
+ }
637
+
638
+ // ... joinLive() 和 leaveLive() 方法 ...
639
+
640
+ override fun onDestroy() {
641
+ super.onDestroy()
642
+ // 5. 确保在 Activity 销毁时移除监听器,防止内存泄漏
643
+ LiveListStore.shared().removeLiveListListener(liveListListener)
644
+ leaveLive()
645
+ Log.d("Live", "YourAudienceActivity onDestroy")
646
+ }
647
+ }
648
+ ```
649
+
650
+ ### 运行效果
651
+
652
+ 集成 **LiveCoreView** 后,您将得到一个纯净的视频渲染视图,它已具备完整的直播业务能力,但没有任何交互 UI。您可以参考下一章节 [丰富直播场景](https://write.woa.com/#789ad452-eaf1-433f-905d-fcb2945c1505) 来完善直播场景。
653
+ <table>
654
+ <tr>
655
+ <td rowspan="1" colSpan="1" ></td>
656
+
657
+ <td rowspan="1" colSpan="1" >**动态宫格布局**</td>
658
+
659
+ <td rowspan="1" colSpan="1" >**浮动小窗布局**</td>
660
+
661
+ <td rowspan="1" colSpan="1" >**固定宫格布局**</td>
662
+
663
+ <td rowspan="1" colSpan="1" >**固定小窗布局**</td>
664
+ </tr>
665
+
666
+ <tr>
667
+ <td rowspan="1" colSpan="1" >**模板 ID**</td>
668
+
669
+ <td rowspan="1" colSpan="1" >600</td>
670
+
671
+ <td rowspan="1" colSpan="1" >601</td>
672
+
673
+ <td rowspan="1" colSpan="1" >800</td>
674
+
675
+ <td rowspan="1" colSpan="1" >801</td>
676
+ </tr>
677
+
678
+ <tr>
679
+ <td rowspan="1" colSpan="1" >**描述**</td>
680
+
681
+ <td rowspan="1" colSpan="1" >默认布局,可根据连麦人数动态调整宫格大小。</td>
682
+
683
+ <td rowspan="1" colSpan="1" >连麦嘉宾以浮动小窗形式显示。</td>
684
+
685
+ <td rowspan="1" colSpan="1" >连麦人数固定,每个嘉宾占据一个固定宫格。</td>
686
+
687
+ <td rowspan="1" colSpan="1" >连麦人数固定,嘉宾以固定小窗形式显示。</td>
688
+ </tr>
689
+
690
+ <tr>
691
+ <td rowspan="1" colSpan="1" >**运行效果**</td>
692
+
693
+ <td rowspan="1" colSpan="1" >![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027182498/394f3851a5b511f09936525400e889b2.png)</td>
694
+
695
+ <td rowspan="1" colSpan="1" >![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027182498/395e0e3da5b511f0930a5254007c27c5.png)</td>
696
+
697
+ <td rowspan="1" colSpan="1" >![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027182498/39427c02a5b511f0b1565254001c06ec.png)</td>
698
+
699
+ <td rowspan="1" colSpan="1" >![](https://write-document-release-1258344699.cos.ap-guangzhou.tencentcos.cn/100027182498/3942f453a5b511f091df5254005ef0f7.png)</td>
700
+ </tr>
701
+ </table>
702
+
703
+
704
+ ## 丰富直播场景
705
+
706
+ 当您完成了基础的直播功能后,您可以参考以下功能指南来为直播添加丰富的互动玩法。
707
+ <table>
708
+ <tr>
709
+ <td rowspan="1" colSpan="1" >**直播功能**</td>
710
+
711
+ <td rowspan="1" colSpan="1" >**功能介绍**</td>
712
+
713
+ <td rowspan="1" colSpan="1" >**功能 Stores**</td>
714
+
715
+ <td rowspan="1" colSpan="1" >**实现指南**</td>
716
+ </tr>
717
+
718
+ <tr>
719
+ <td rowspan="1" colSpan="1" >**实现观众音视频连线**</td>
720
+
721
+ <td rowspan="1" colSpan="1" >观众申请上麦,与主播进行实时视频互动。</td>
722
+
723
+ <td rowspan="1" colSpan="1" >[CoGuestStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-co-guest-store/index.html)</td>
724
+
725
+ <td rowspan="1" colSpan="1" >[观众连线](https://write.woa.com/document/191126685644365824)</td>
726
+ </tr>
727
+
728
+ <tr>
729
+ <td rowspan="1" colSpan="1" >**实现主播跨房连线 PK**</td>
730
+
731
+ <td rowspan="1" colSpan="1" >两个不同房间的主播进行连线,实现互动或 PK。</td>
732
+
733
+ <td rowspan="1" colSpan="1" >[CoHostStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-co-host-store/index.html)<br>[BattleStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-battle-store/index.html)</td>
734
+
735
+ <td rowspan="1" colSpan="1" >[主播连线 & PK](https://write.woa.com/document/191126527339847680)</td>
736
+ </tr>
737
+
738
+ <tr>
739
+ <td rowspan="1" colSpan="1" >**添加弹幕聊天功能**</td>
740
+
741
+ <td rowspan="1" colSpan="1" >观众可以在直播间发送和接收实时文字消息。</td>
742
+
743
+ <td rowspan="1" colSpan="1" >[BarrageStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.barrage/-barrage-store/index.html)</td>
744
+
745
+ <td rowspan="1" colSpan="1" >[实现弹幕功能](https://write.woa.com/document/191126771034308608)</td>
746
+ </tr>
747
+
748
+ <tr>
749
+ <td rowspan="1" colSpan="1" >**构建礼物赠送系统**</td>
750
+
751
+ <td rowspan="1" colSpan="1" >观众可以向主播赠送虚拟礼物,增加互动和趣味性。</td>
752
+
753
+ <td rowspan="1" colSpan="1" >[GiftStore](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.gift/-gift-store/index.html)</td>
754
+
755
+ <td rowspan="1" colSpan="1" >[实现礼物功能](https://write.woa.com/document/191126992871682048)</td>
756
+ </tr>
757
+ </table>
758
+
759
+
760
+ ## API 文档
761
+ <table>
762
+ <tr>
763
+ <td rowspan="1" colSpan="1" >**Store/Component**</td>
764
+
765
+ <td rowspan="1" colSpan="1" >**功能描述**</td>
766
+
767
+ <td rowspan="1" colSpan="1" >**API 文档**</td>
768
+ </tr>
769
+
770
+ <tr>
771
+ <td rowspan="1" colSpan="1" >**LiveCoreView**</td>
772
+
773
+ <td rowspan="1" colSpan="1" >直播视频流展示与交互的核心视图组件:负责视频流渲染和视图挂件处理,支持主播直播、观众连麦、主播连线等场景。</td>
774
+
775
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.view/-live-core-view/index.html)</td>
776
+ </tr>
777
+
778
+ <tr>
779
+ <td rowspan="1" colSpan="1" >**LiveListStore**</td>
780
+
781
+ <td rowspan="1" colSpan="1" >直播间全生命周期管理:创建 / 加入 / 离开 / 销毁房间,查询房间列表,修改直播信息(名称、公告等),监听直播状态(如被踢出、结束)。</td>
782
+
783
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-live-list-store/index.html)</td>
784
+ </tr>
785
+
786
+ <tr>
787
+ <td rowspan="1" colSpan="1" >**DeviceStore**</td>
788
+
789
+ <td rowspan="1" colSpan="1" >音视频设备控制:麦克风(开关 / 音量)、摄像头(开关 / 切换 / 画质)、屏幕共享,设备状态实时监听。</td>
790
+
791
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.device/-device-store/index.html)</td>
792
+ </tr>
793
+
794
+ <tr>
795
+ <td rowspan="1" colSpan="1" >**CoGuestStore**</td>
796
+
797
+ <td rowspan="1" colSpan="1" >观众连麦管理:连麦申请 / 邀请 / 同意 / 拒绝,连麦成员权限控制(麦克风 / 摄像头),状态同步。</td>
798
+
799
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-co-guest-store/index.html)</td>
800
+ </tr>
801
+
802
+ <tr>
803
+ <td rowspan="1" colSpan="1" >**CoHostStore**</td>
804
+
805
+ <td rowspan="1" colSpan="1" >主播跨房连线:支持多布局模板(动态网格等),发起 / 接受 / 拒绝连线,连麦主播互动管理。</td>
806
+
807
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-co-host-store/index.html)</td>
808
+ </tr>
809
+
810
+ <tr>
811
+ <td rowspan="1" colSpan="1" >**BattleStore**</td>
812
+
813
+ <td rowspan="1" colSpan="1" >主播 PK 对战:发起 PK(配置时长 / 对手),管理 PK 状态(开始 / 结束),同步分数,监听对战结果。</td>
814
+
815
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-battle-store/index.html)</td>
816
+ </tr>
817
+
818
+ <tr>
819
+ <td rowspan="1" colSpan="1" >**GiftStore**</td>
820
+
821
+ <td rowspan="1" colSpan="1" >礼物互动:获取礼物列表,发送 / 接收礼物,监听礼物事件(含发送者、礼物详情)。</td>
822
+
823
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.gift/-gift-store/index.html)</td>
824
+ </tr>
825
+
826
+ <tr>
827
+ <td rowspan="1" colSpan="1" >**BarrageStore**</td>
828
+
829
+ <td rowspan="1" colSpan="1" >弹幕功能:发送文本 / 自定义弹幕,维护弹幕列表,实时监听弹幕状态。</td>
830
+
831
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.barrage/-barrage-store/index.html)</td>
832
+ </tr>
833
+
834
+ <tr>
835
+ <td rowspan="1" colSpan="1" >**LikeStore**</td>
836
+
837
+ <td rowspan="1" colSpan="1" >点赞互动:发送点赞,监听点赞事件,同步总点赞数。</td>
838
+
839
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-like-store/index.html)</td>
840
+ </tr>
841
+
842
+ <tr>
843
+ <td rowspan="1" colSpan="1" >**LiveAudienceStore**</td>
844
+
845
+ <td rowspan="1" colSpan="1" >观众管理:获取实时观众列表(ID / 名称 / 头像),统计观众数量,监听观众进出事件。</td>
846
+
847
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-live-audience-store/index.html)</td>
848
+ </tr>
849
+
850
+ <tr>
851
+ <td rowspan="1" colSpan="1" >**AudioEffectStore**</td>
852
+
853
+ <td rowspan="1" colSpan="1" >音频特效:变声(童声 / 男声)、混响(KTV 等)、耳返调节,实时切换特效。</td>
854
+
855
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.device/-audio-effect-store/index.html)</td>
856
+ </tr>
857
+
858
+ <tr>
859
+ <td rowspan="1" colSpan="1" >**BaseBeautyStore**</td>
860
+
861
+ <td rowspan="1" colSpan="1" >基础美颜:调节磨皮 / 美白 / 红润(0-100 级),重置美颜状态,同步效果参数。</td>
862
+
863
+ <td rowspan="1" colSpan="1" >[API 文档](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.device/-base-beauty-store/index.html)</td>
864
+ </tr>
865
+ </table>
866
+
867
+
868
+ ## 常见问题
869
+
870
+ ### 主播调用 createLive 或 观众调用 joinLive 后为什么画面是黑的,没有视频画面?
871
+ - **检查 setLiveID**:请确保在调用开播或观看接口前,已经为 LiveCoreView 实例设置了正确的 liveID。
872
+
873
+ - **检查设备权限**:请确保 App 已获得摄像头和麦克风的系统使用权限。
874
+
875
+ - **检查主播端**:主播端是否正常调用 `DeviceStore.shared().openLocalCamera(true)` 打开了摄像头。
876
+
877
+ - **检查网络**:请检查设备网络连接是否正常。
878
+
879
+
880
+ ### 主播端打开摄像头后,开播后可以看到本地视频预览画面,开播前视频预览是黑屏?
881
+ - **检查主播端**:请检查主播推流视图`LiveCoreView` 的 `viewType`是否配置为`PUSH_VIEW`。
882
+
883
+ - **检查观众端**:请检查观众拉流视图`LiveCoreView` 的 `viewType`是否配置为 `PLAY_VIEW`。