@tencent-rtc/mcp 1.3.2 → 1.3.4
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.
- package/package.json +1 -1
- package/resource/doc/livekit/live/android/live-audience-list.md +334 -0
- package/resource/doc/livekit/live/android/live-audio-effect.md +380 -0
- package/resource/doc/livekit/live/android/live-barrage.md +565 -0
- package/resource/doc/livekit/live/android/live-base-beauty.md +275 -0
- package/resource/doc/livekit/live/android/live-co-guest-interaction.md +629 -0
- package/resource/doc/livekit/live/android/live-gift.md +822 -0
- package/resource/doc/livekit/live/android/live-host-interaction.md +888 -0
- package/resource/doc/livekit/live/android/live-integration.md +972 -0
- package/resource/doc/livekit/live/android/live-live-list.md +575 -0
- package/resource/doc/livekit/live/android/workflow.md +189 -0
- package/tools/common/record-prompt.js +2 -2
- package/tools/common/record-prompt.js.map +1 -1
- package/tools/definitions/get_native_live_extra_features_def.js +87 -0
- package/tools/definitions/get_native_live_extra_features_def.js.map +1 -0
- package/tools/definitions/get_native_live_interaction_def.js +74 -0
- package/tools/definitions/get_native_live_interaction_def.js.map +1 -0
- package/tools/definitions/get_native_live_uikit_integration_def.js +49 -0
- package/tools/definitions/get_native_live_uikit_integration_def.js.map +1 -0
- package/tools/definitions/record_prompt_def.js +42 -11
- package/tools/definitions/record_prompt_def.js.map +1 -1
- package/tools/definitions/record_result_def.js +1 -1
- package/tools/index.js +6 -0
- package/tools/index.js.map +1 -1
- package/tools/live/get-native-live-uikit-integration.js +101 -0
- package/tools/live/get-native-live-uikit-integration.js.map +1 -0
- package/tools/live/get-web-live-component-detail.js +1 -1
- package/tools/live/get-web-live-component-detail.js.map +1 -1
- package/tools/live/get-web-live-state-detail.js +1 -1
- package/tools/live/get-web-live-state-detail.js.map +1 -1
- package/tools/live/get-web-live-uikit-integration.js +6 -6
- package/tools/live/get-web-live-uikit-integration.js.map +1 -1
- package/tools/live/get_native_live_extra_features.js +105 -0
- package/tools/live/get_native_live_extra_features.js.map +1 -0
- package/tools/live/get_native_live_interaction.js +101 -0
- package/tools/live/get_native_live_interaction.js.map +1 -0
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
- /package/resource/doc/livekit/{vue → live/vue}/components/barrage.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/components/co-guest-panel.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/components/live-audience-list.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/components/live-scene-panel.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/components/live-view.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/components/stream-mixer.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/faq.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/live-list-integration.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/live-player-desk-integration.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/live-player-h5-integration.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/live-pusher-integration.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/states/live-state.md +0 -0
- /package/resource/doc/livekit/{vue → live/vue}/workflow.md +0 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
`LiveListStore` is the core module of **AtomicXCore** responsible for managing the live room list, creating and joining rooms, and maintaining room state. With LiveListStore, you can implement comprehensive live streaming lifecycle management in your application.
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Core Features
|
|
7
|
+
- **Live Room List Fetching**: Retrieve a paginated list of all currently public live rooms.
|
|
8
|
+
|
|
9
|
+
- **Live Lifecycle Management**: Provides a complete set of interfaces for the entire live streaming workflow, including room creation, going live, joining, leaving, and ending a live session.
|
|
10
|
+
|
|
11
|
+
- **Real-Time Event Listening**: Listen for key events such as live session end or users being removed from a room.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Core Concepts
|
|
15
|
+
<table>
|
|
16
|
+
<tr>
|
|
17
|
+
<td rowspan="1" colSpan="1" >**Core Concept**</td>
|
|
18
|
+
|
|
19
|
+
<td rowspan="1" colSpan="1" >**Type**</td>
|
|
20
|
+
|
|
21
|
+
<td rowspan="1" colSpan="1" >**Core Responsibility & Description**</td>
|
|
22
|
+
</tr>
|
|
23
|
+
|
|
24
|
+
<tr>
|
|
25
|
+
<td rowspan="1" colSpan="1" >`LiveInfo`</td>
|
|
26
|
+
|
|
27
|
+
<td rowspan="1" colSpan="1" >`data class`</td>
|
|
28
|
+
|
|
29
|
+
<td rowspan="1" colSpan="1" >Represents the complete information model of a live room. Includes the live room ID (liveID), name (liveName), owner information (liveOwner), and custom metadata (metaData), among other properties.</td>
|
|
30
|
+
</tr>
|
|
31
|
+
|
|
32
|
+
<tr>
|
|
33
|
+
<td rowspan="1" colSpan="1" >`LiveListState`</td>
|
|
34
|
+
|
|
35
|
+
<td rowspan="1" colSpan="1" >`data class`</td>
|
|
36
|
+
|
|
37
|
+
<td rowspan="1" colSpan="1" >Represents the current state of the live list module. The core property liveList is a StateFlow containing the fetched live room list; currentLive represents the information of the live room the user is currently in.</td>
|
|
38
|
+
</tr>
|
|
39
|
+
|
|
40
|
+
<tr>
|
|
41
|
+
<td rowspan="1" colSpan="1" >`LiveListListener`</td>
|
|
42
|
+
|
|
43
|
+
<td rowspan="1" colSpan="1" >`abstract class`</td>
|
|
44
|
+
|
|
45
|
+
<td rowspan="1" colSpan="1" >Handles global live room events, including onLiveEnded (live ended) and onKickedOutOfLive (user removed from live), for responding to key room state changes.</td>
|
|
46
|
+
</tr>
|
|
47
|
+
|
|
48
|
+
<tr>
|
|
49
|
+
<td rowspan="1" colSpan="1" >`LiveListStore`</td>
|
|
50
|
+
|
|
51
|
+
<td rowspan="1" colSpan="1" >`abstract class`</td>
|
|
52
|
+
|
|
53
|
+
<td rowspan="1" colSpan="1" >The core management class for interacting with the live room list and room lifecycle. It is a global singleton responsible for all operations such as creating, joining, and updating live room information.</td>
|
|
54
|
+
</tr>
|
|
55
|
+
</table>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Implementation
|
|
59
|
+
|
|
60
|
+
### Step 1: Component Integration
|
|
61
|
+
- **Video Live Streaming**:Refer to [Quick Start](https://write.woa.com/document/194571606056804352) to integrate AtomicXCore and complete the implementation of the [Host Video Streaming](https://write.woa.com/document/194571606056804352) and [Audience Join and Watch](https://write.woa.com/document/194571606056804352) features.
|
|
62
|
+
|
|
63
|
+
- **Voice Chat Room**:Refer to [Quick Start](https://write.woa.com/document/194571595678187521) to integrate AtomicXCore and complete the implementation of the [Host Audio Streaming](https://write.woa.com/document/194571595678187521) and [Audience Join and Watch](https://write.woa.com/document/194571595678187521) features.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Step 2: Implement Audience Entry from Live Room List
|
|
67
|
+
|
|
68
|
+
Create a page to display the live room list using RecyclerView to layout live room cards. When a user taps a card, retrieve the liveId for that room and navigate to the audience viewing page.
|
|
69
|
+
``` kotlin
|
|
70
|
+
import android.content.Intent
|
|
71
|
+
import android.os.Bundle
|
|
72
|
+
import android.view.LayoutInflater
|
|
73
|
+
import android.view.View
|
|
74
|
+
import android.view.ViewGroup
|
|
75
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
76
|
+
import androidx.recyclerview.widget.GridLayoutManager
|
|
77
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
78
|
+
import io.trtc.tuikit.atomicxcore.api.CompletionHandler
|
|
79
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
|
|
80
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
|
|
81
|
+
import kotlinx.coroutines.*
|
|
82
|
+
import kotlinx.coroutines.flow.*
|
|
83
|
+
|
|
84
|
+
class LiveListActivity : AppCompatActivity() {
|
|
85
|
+
private val liveListStore = LiveListStore.shared()
|
|
86
|
+
private var liveList: List<LiveInfo> = emptyList()
|
|
87
|
+
private val coroutineScope = CoroutineScope(Dispatchers.Main)
|
|
88
|
+
|
|
89
|
+
private lateinit var recyclerView: RecyclerView
|
|
90
|
+
private lateinit var adapter: LiveListAdapter
|
|
91
|
+
|
|
92
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
93
|
+
super.onCreate(savedInstanceState)
|
|
94
|
+
setContentView(R.layout.activity_live_list)
|
|
95
|
+
setupUI()
|
|
96
|
+
bindStore()
|
|
97
|
+
fetchLiveList()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private fun bindStore() {
|
|
101
|
+
// Subscribe to the state to automatically receive list updates
|
|
102
|
+
coroutineScope.launch {
|
|
103
|
+
liveListStore.liveState.liveList.collect { fetchedList ->
|
|
104
|
+
liveList = fetchedList
|
|
105
|
+
adapter.notifyDataSetChanged()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun fetchLiveList() {
|
|
111
|
+
liveListStore.fetchLiveList(
|
|
112
|
+
cursor = "",
|
|
113
|
+
count = 20,
|
|
114
|
+
completion = object : CompletionHandler {
|
|
115
|
+
override fun onSuccess() {
|
|
116
|
+
println("Live room list fetched successfully")
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
override fun onFailure(code: Int, desc: String) {
|
|
120
|
+
println("Failed to fetch live room list: $desc")
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// When a user clicks an item in the list
|
|
127
|
+
private fun onLiveItemClick(liveInfo: LiveInfo) {
|
|
128
|
+
// Create the audience viewing page and pass the liveId
|
|
129
|
+
val intent = Intent(this, YourAudienceActivity::class.java)
|
|
130
|
+
intent.putExtra("liveId", liveInfo.liveID)
|
|
131
|
+
startActivity(intent)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
// --- RecyclerView related methods ---
|
|
136
|
+
private fun setupUI() {
|
|
137
|
+
recyclerView = findViewById(R.id.recyclerView)
|
|
138
|
+
adapter = LiveListAdapter(liveList) { liveInfo ->
|
|
139
|
+
onLiveItemClick(liveInfo)
|
|
140
|
+
}
|
|
141
|
+
recyclerView.layoutManager = GridLayoutManager(this, 2)
|
|
142
|
+
recyclerView.adapter = adapter
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
override fun onDestroy() {
|
|
146
|
+
super.onDestroy()
|
|
147
|
+
coroutineScope.cancel()
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// RecyclerView Adapter
|
|
152
|
+
class LiveListAdapter(
|
|
153
|
+
private var liveList: List<LiveInfo>,
|
|
154
|
+
private val onItemClick: (LiveInfo) -> Unit
|
|
155
|
+
) : RecyclerView.Adapter<LiveListAdapter.LiveViewHolder>() {
|
|
156
|
+
|
|
157
|
+
class LiveViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|
158
|
+
// Define your ViewHolder view components
|
|
159
|
+
// val titleTextView: TextView = itemView.findViewById(R.id.titleTextView)
|
|
160
|
+
// val coverImageView: ImageView = itemView.findViewById(R.id.coverImageView)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LiveViewHolder {
|
|
164
|
+
val view = LayoutInflater.from(parent.context)
|
|
165
|
+
.inflate(R.layout.item_live_card, parent, false)
|
|
166
|
+
return LiveViewHolder(view)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
override fun onBindViewHolder(holder: LiveViewHolder, position: Int) {
|
|
170
|
+
val liveInfo = liveList[position]
|
|
171
|
+
// Set data to ViewHolder
|
|
172
|
+
// holder.titleTextView.text = liveInfo.liveName
|
|
173
|
+
// Load cover image, etc.
|
|
174
|
+
|
|
175
|
+
holder.itemView.setOnClickListener {
|
|
176
|
+
onItemClick(liveInfo)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
override fun getItemCount(): Int = liveList.size
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### LiveInfo Parameter Reference
|
|
185
|
+
<table>
|
|
186
|
+
<tr>
|
|
187
|
+
<td rowspan="1" colSpan="1" >**Parameter Name**</td>
|
|
188
|
+
|
|
189
|
+
<td rowspan="1" colSpan="1" >**Type**</td>
|
|
190
|
+
|
|
191
|
+
<td rowspan="1" colSpan="1" >**Description**</td>
|
|
192
|
+
</tr>
|
|
193
|
+
|
|
194
|
+
<tr>
|
|
195
|
+
<td rowspan="1" colSpan="1" >`liveID`</td>
|
|
196
|
+
|
|
197
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
198
|
+
|
|
199
|
+
<td rowspan="1" colSpan="1" >Unique identifier for the live room</td>
|
|
200
|
+
</tr>
|
|
201
|
+
|
|
202
|
+
<tr>
|
|
203
|
+
<td rowspan="1" colSpan="1" >`liveName`</td>
|
|
204
|
+
|
|
205
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
206
|
+
|
|
207
|
+
<td rowspan="1" colSpan="1" >Title of the live room</td>
|
|
208
|
+
</tr>
|
|
209
|
+
|
|
210
|
+
<tr>
|
|
211
|
+
<td rowspan="1" colSpan="1" >`coverURL`</td>
|
|
212
|
+
|
|
213
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
214
|
+
|
|
215
|
+
<td rowspan="1" colSpan="1" >Cover image URL for the live room</td>
|
|
216
|
+
</tr>
|
|
217
|
+
|
|
218
|
+
<tr>
|
|
219
|
+
<td rowspan="1" colSpan="1" >`liveOwner`</td>
|
|
220
|
+
|
|
221
|
+
<td rowspan="1" colSpan="1" >[LiveUserInfo](https://tencent-rtc.github.io/TUIKit_Android/-atomic-x%20-core%20-a-p-i/io.trtc.tuikit.atomicxcore.api.live/-live-user-info/index.html)</td>
|
|
222
|
+
|
|
223
|
+
<td rowspan="1" colSpan="1" >Personal information of the room owner</td>
|
|
224
|
+
</tr>
|
|
225
|
+
|
|
226
|
+
<tr>
|
|
227
|
+
<td rowspan="1" colSpan="1" >`totalViewerCount`</td>
|
|
228
|
+
|
|
229
|
+
<td rowspan="1" colSpan="1" >`Int`</td>
|
|
230
|
+
|
|
231
|
+
<td rowspan="1" colSpan="1" >Total number of viewers in the live room</td>
|
|
232
|
+
</tr>
|
|
233
|
+
|
|
234
|
+
<tr>
|
|
235
|
+
<td rowspan="1" colSpan="1" >`categoryList`</td>
|
|
236
|
+
|
|
237
|
+
<td rowspan="1" colSpan="1" >`List<Int>`</td>
|
|
238
|
+
|
|
239
|
+
<td rowspan="1" colSpan="1" >List of category tags for the live room</td>
|
|
240
|
+
</tr>
|
|
241
|
+
|
|
242
|
+
<tr>
|
|
243
|
+
<td rowspan="1" colSpan="1" >`notice`</td>
|
|
244
|
+
|
|
245
|
+
<td rowspan="1" colSpan="1" >`String`</td>
|
|
246
|
+
|
|
247
|
+
<td rowspan="1" colSpan="1" >Announcement information for the live room</td>
|
|
248
|
+
</tr>
|
|
249
|
+
|
|
250
|
+
<tr>
|
|
251
|
+
<td rowspan="1" colSpan="1" >`metaData`</td>
|
|
252
|
+
|
|
253
|
+
<td rowspan="1" colSpan="1" >`Map<String, String>`</td>
|
|
254
|
+
|
|
255
|
+
<td rowspan="1" colSpan="1" >Developer-defined metadata for implementing advanced business scenarios</td>
|
|
256
|
+
</tr>
|
|
257
|
+
</table>
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
## Advanced Features
|
|
261
|
+
|
|
262
|
+
### Scenario 1: Category Filtering for Live Room List
|
|
263
|
+
|
|
264
|
+
On the live plaza page, users can select category tags such as "Hot", "Music", "Games", etc. When a tag is selected, the live room list dynamically filters to display only rooms in the chosen category, helping users quickly discover relevant content.
|
|
265
|
+
|
|
266
|
+

|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
#### Implementation
|
|
270
|
+
|
|
271
|
+
Use the `categoryList` property in the `LiveInfo` model. When the host selects a category while going live, the `fetchLiveList` API returns LiveInfo objects that include these category details. After retrieving the full live room list, filter it on the client based on the user’s selected category and refresh the UI.
|
|
272
|
+
|
|
273
|
+
#### Code Example
|
|
274
|
+
|
|
275
|
+
The following example shows how to extend a `LiveListManager` within `LiveListActivity` to handle data retrieval and filtering logic.
|
|
276
|
+
``` kotlin
|
|
277
|
+
import android.os.Bundle
|
|
278
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
279
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
280
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
|
|
281
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveListStore
|
|
282
|
+
import kotlinx.coroutines.*
|
|
283
|
+
import kotlinx.coroutines.flow.*
|
|
284
|
+
|
|
285
|
+
// 1. Create a data manager to encapsulate data retrieval and filtering logic
|
|
286
|
+
class LiveListManager {
|
|
287
|
+
private val liveListStore = LiveListStore.shared()
|
|
288
|
+
private var fullLiveList: List<LiveInfo> = emptyList()
|
|
289
|
+
|
|
290
|
+
// Expose the final filtered live list externally
|
|
291
|
+
private val _filteredLiveList = MutableStateFlow<List<LiveInfo>>(emptyList())
|
|
292
|
+
val filteredLiveList: StateFlow<List<LiveInfo>> = _filteredLiveList
|
|
293
|
+
|
|
294
|
+
init {
|
|
295
|
+
// Listen for full list changes
|
|
296
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
297
|
+
liveListStore.liveState.liveList.collect { fetchedList ->
|
|
298
|
+
fullLiveList = fetchedList
|
|
299
|
+
// By default, publish the complete list
|
|
300
|
+
_filteredLiveList.value = fetchedList
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
fun fetchFirstPage() {
|
|
306
|
+
liveListStore.fetchLiveList(cursor = "", count = 20, completion = null)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/// Filter the live list by category
|
|
310
|
+
fun filterLiveList(categoryId: Int?) {
|
|
311
|
+
if (categoryId == null) {
|
|
312
|
+
// If categoryId is null, show the complete list
|
|
313
|
+
_filteredLiveList.value = fullLiveList
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
val filteredList = fullLiveList.filter { liveInfo ->
|
|
318
|
+
liveInfo.categoryList.contains(categoryId)
|
|
319
|
+
}
|
|
320
|
+
_filteredLiveList.value = filteredList
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// 2. Use the Manager in your LiveListActivity
|
|
325
|
+
class LiveListActivity : AppCompatActivity() {
|
|
326
|
+
private val manager = LiveListManager()
|
|
327
|
+
private lateinit var recyclerView: RecyclerView
|
|
328
|
+
|
|
329
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
330
|
+
super.onCreate(savedInstanceState)
|
|
331
|
+
setContentView(R.layout.activity_live_list)
|
|
332
|
+
// setupUI()
|
|
333
|
+
|
|
334
|
+
// Bind data
|
|
335
|
+
CoroutineScope(Dispatchers.Main).launch {
|
|
336
|
+
manager.filteredLiveList.collect { filteredList ->
|
|
337
|
+
// Refresh UI
|
|
338
|
+
// adapter.updateList(filteredList)
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Fetch first page
|
|
343
|
+
manager.fetchFirstPage()
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// When the user clicks a top category tag
|
|
347
|
+
fun onCategorySelected(categoryId: Int) {
|
|
348
|
+
manager.filterLiveList(categoryId)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ... (RecyclerView related code)
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Scenario 2: Swipe-to-Play for Live Room List
|
|
356
|
+
|
|
357
|
+
Users can switch between live rooms by swiping up and down. When a new live room is centered on the screen, the video preview automatically starts playing. When it leaves the screen, playback stops automatically to save bandwidth and device resources.
|
|
358
|
+
|
|
359
|
+
> **Note:**
|
|
360
|
+
>
|
|
361
|
+
|
|
362
|
+
> **Swipe-to-Play **is currently only supported for Video Live Streaming.
|
|
363
|
+
>
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
#### Interaction Flow
|
|
367
|
+
|
|
368
|
+

|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
#### Implementation
|
|
372
|
+
|
|
373
|
+
`LiveCoreView` supports multiple instances. Create a separate `LiveCoreView` for each `RecyclerView.ViewHolder`. By monitoring the scroll state of the `RecyclerView`, you can precisely control when to start or stop streaming in each ViewHolder, achieving "play on swipe in, stop on swipe out" behavior.
|
|
374
|
+
|
|
375
|
+
#### Code Example
|
|
376
|
+
|
|
377
|
+
We create a custom `LiveFeedViewHolder` that holds a `LiveCoreView` internally. We then manage the playback state of these ViewHolders in the `Activity`.
|
|
378
|
+
``` kotlin
|
|
379
|
+
import android.os.Bundle
|
|
380
|
+
import android.view.LayoutInflater
|
|
381
|
+
import android.view.View
|
|
382
|
+
import android.view.ViewGroup
|
|
383
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
384
|
+
import androidx.recyclerview.widget.LinearLayoutManager
|
|
385
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
386
|
+
import io.trtc.tuikit.atomicxcore.api.live.LiveInfo
|
|
387
|
+
import io.trtc.tuikit.atomicxcore.api.view.CoreViewType
|
|
388
|
+
import io.trtc.tuikit.atomicxcore.api.view.LiveCoreView
|
|
389
|
+
|
|
390
|
+
// 1. Custom RecyclerView.ViewHolder, containing a LiveCoreView internally
|
|
391
|
+
class LiveFeedViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|
392
|
+
private var liveCoreView: LiveCoreView? = null
|
|
393
|
+
|
|
394
|
+
fun setLiveInfo(liveInfo: LiveInfo) {
|
|
395
|
+
// Create a new LiveCoreView for the new live info
|
|
396
|
+
liveCoreView = LiveCoreView(itemView.context, viewType = CoreViewType.PLAY_VIEW)
|
|
397
|
+
liveCoreView?.let { view ->
|
|
398
|
+
(itemView as ViewGroup).addView(view)
|
|
399
|
+
view.layoutParams = ViewGroup.LayoutParams(
|
|
400
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
401
|
+
ViewGroup.LayoutParams.MATCH_PARENT
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
fun startPlay(roomId: String) {
|
|
407
|
+
liveCoreView?.startPreviewLiveStream(roomId, false, callback = null)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
fun stopPlay(roomId: String) {
|
|
411
|
+
liveCoreView?.stopPreviewLiveStream(roomId)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// 2. Manage playback logic in the Activity
|
|
416
|
+
class LiveFeedActivity : AppCompatActivity() {
|
|
417
|
+
|
|
418
|
+
private lateinit var recyclerView: RecyclerView
|
|
419
|
+
private var liveList: List<LiveInfo> = emptyList()
|
|
420
|
+
private var currentPlayingPosition: Int = -1
|
|
421
|
+
|
|
422
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
423
|
+
super.onCreate(savedInstanceState)
|
|
424
|
+
setContentView(R.layout.activity_live_feed)
|
|
425
|
+
setupRecyclerView()
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private fun setupRecyclerView() {
|
|
429
|
+
recyclerView = findViewById(R.id.recyclerView)
|
|
430
|
+
recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
|
431
|
+
recyclerView.adapter = LiveFeedAdapter(liveList) { position ->
|
|
432
|
+
playVideoAtPosition(position)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Listen for scroll state
|
|
436
|
+
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
437
|
+
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
|
438
|
+
super.onScrollStateChanged(recyclerView, newState)
|
|
439
|
+
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
|
440
|
+
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
|
441
|
+
val firstVisiblePosition = layoutManager.findFirstCompletelyVisibleItemPosition()
|
|
442
|
+
if (firstVisiblePosition != RecyclerView.NO_POSITION) {
|
|
443
|
+
playVideoAtPosition(firstVisiblePosition)
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
})
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
private fun playVideoAtPosition(position: Int) {
|
|
451
|
+
// Only switch playback when the centered position changes
|
|
452
|
+
if (currentPlayingPosition != position) {
|
|
453
|
+
// Stop current playback
|
|
454
|
+
if (currentPlayingPosition != -1) {
|
|
455
|
+
val currentViewHolder = recyclerView.findViewHolderForAdapterPosition(currentPlayingPosition)
|
|
456
|
+
if (currentViewHolder is LiveFeedViewHolder) {
|
|
457
|
+
val liveInfo = liveList[currentPlayingPosition]
|
|
458
|
+
currentViewHolder.stopPlay(liveInfo.liveID)
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Start new playback
|
|
463
|
+
val newViewHolder = recyclerView.findViewHolderForAdapterPosition(position)
|
|
464
|
+
if (newViewHolder is LiveFeedViewHolder) {
|
|
465
|
+
val liveInfo = liveList[position]
|
|
466
|
+
newViewHolder.startPlay(liveInfo.liveID)
|
|
467
|
+
currentPlayingPosition = position
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// RecyclerView Adapter
|
|
473
|
+
inner class LiveFeedAdapter(
|
|
474
|
+
private var liveList: List<LiveInfo>,
|
|
475
|
+
private val onItemClick: (Int) -> Unit
|
|
476
|
+
) : RecyclerView.Adapter<LiveFeedViewHolder>() {
|
|
477
|
+
|
|
478
|
+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LiveFeedViewHolder {
|
|
479
|
+
val view = LayoutInflater.from(parent.context)
|
|
480
|
+
.inflate(R.layout.item_live_feed, parent, false)
|
|
481
|
+
return LiveFeedViewHolder(view)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
override fun onBindViewHolder(holder: LiveFeedViewHolder, position: Int) {
|
|
485
|
+
val liveInfo = liveList[position]
|
|
486
|
+
holder.setLiveInfo(liveInfo)
|
|
487
|
+
holder.itemView.setOnClickListener {
|
|
488
|
+
onItemClick(position)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
override fun getItemCount(): Int = liveList.size
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## API Documentation
|
|
498
|
+
|
|
499
|
+
For detailed information on all public interfaces, properties, and methods of [LiveListStore](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) and related classes, refer to the official API documentation included with the [AtomicXCore](https://tencent-rtc.github.io/TUIKit_Android/index.html) framework. The relevant Stores used in this document are as follows:
|
|
500
|
+
<table>
|
|
501
|
+
<tr>
|
|
502
|
+
<td rowspan="1" colSpan="1" >**Store/Component**</td>
|
|
503
|
+
|
|
504
|
+
<td rowspan="1" colSpan="1" >**Feature Description**</td>
|
|
505
|
+
|
|
506
|
+
<td rowspan="1" colSpan="1" >**API Documentation**</td>
|
|
507
|
+
</tr>
|
|
508
|
+
|
|
509
|
+
<tr>
|
|
510
|
+
<td rowspan="1" colSpan="1" >LiveCoreView</td>
|
|
511
|
+
|
|
512
|
+
<td rowspan="1" colSpan="1" >Core view component for live video stream display and interaction. Responsible for video stream rendering and view widget handling, supporting scenarios such as host streaming, audience co-hosting, and host linking.</td>
|
|
513
|
+
|
|
514
|
+
<td rowspan="1" colSpan="1" >[API Documentation](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>
|
|
515
|
+
</tr>
|
|
516
|
+
|
|
517
|
+
<tr>
|
|
518
|
+
<td rowspan="1" colSpan="1" >LiveListStore</td>
|
|
519
|
+
|
|
520
|
+
<td rowspan="1" colSpan="1" >Full lifecycle management of live rooms: create, join, leave, destroy rooms; query room list; modify live information (name, announcement, etc.); listen to live status (such as being removed or ended).</td>
|
|
521
|
+
|
|
522
|
+
<td rowspan="1" colSpan="1" >[API Documentation](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>
|
|
523
|
+
</tr>
|
|
524
|
+
</table>
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
## FAQs
|
|
528
|
+
|
|
529
|
+
### Is the list data for voice chat rooms and video live rooms the same?
|
|
530
|
+
|
|
531
|
+
Yes. The data is unified; you do not need to fetch them separately. LiveListStore is a global singleton that manages the lifecycle of all "live" rooms in your application, including both video live rooms and voice chat rooms.
|
|
532
|
+
|
|
533
|
+
### How do I distinguish between voice chat rooms and video live rooms in the live room list?
|
|
534
|
+
|
|
535
|
+
`LiveListStore` does not differentiate between room business types. You must filter and categorize the list after fetching, at the application or UI layer.
|
|
536
|
+
|
|
537
|
+
We recommend two approaches:
|
|
538
|
+
|
|
539
|
+
**Approach 1 (Recommended): Use seatLayoutTemplateID for differentiation.**
|
|
540
|
+
|
|
541
|
+
This template ID defines the room layout. For supported template IDs and effects, refer to [Run And Test](https://write.woa.com/document/194571606056804352).
|
|
542
|
+
- **Step 1: Specify ID when creating a room**
|
|
543
|
+
|
|
544
|
+
- When calling `LiveListStore.shared.createLive`, set the `seatLayoutTemplateID` property of `LiveInfo` based on your business scenario:
|
|
545
|
+
|
|
546
|
+
- Voice chat rooms: Use template IDs in the range 1–199.
|
|
547
|
+
|
|
548
|
+
- Video live rooms: Use template IDs in the range 200–999.
|
|
549
|
+
|
|
550
|
+
- **Step 2: Filter when fetching the list**
|
|
551
|
+
|
|
552
|
+
- On the client side, after receiving the list in `LiveListStore.state.liveList`, determine the business scenario by checking the template ID range.
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
> **Note:**
|
|
556
|
+
>
|
|
557
|
+
|
|
558
|
+
> If the seatLayoutTemplateID does not match your business scenario (voice chat room or video live room), seat layout features may not work as expected.
|
|
559
|
+
>
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
**Approach 2:****Add a business prefix to **`liveID`**.**
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
This is an optional, application-layer convention to help you filter rooms quickly.
|
|
566
|
+
|
|
567
|
+
- **Step 1: Add prefix when creating a room**
|
|
568
|
+
|
|
569
|
+
- When generating liveID and calling createLive, assign different prefixes for each business type. For example: video live room IDs start with "Live_" (e.g., Live_12345), voice chat room IDs start with "voice_" (e.g., voice_67890).
|
|
570
|
+
|
|
571
|
+
- **Step 2: Check prefix when fetching the list**
|
|
572
|
+
|
|
573
|
+
- On the client side, after fetching the list, distinguish rooms by checking the liveID prefix.
|
|
574
|
+
|
|
575
|
+
|