Live Room Switching | Live Viewing |
![]() |
![]() |
TUILiveKit trial version or activate the paid version.import android.os.Bundleimport android.util.Logimport androidx.appcompat.app.AppCompatActivityimport com.trtc.uikit.livekit.livelist.LiveListViewimport io.trtc.tuikit.atomicxcore.api.CompletionHandlerimport io.trtc.tuikit.atomicxcore.api.live.LiveListStoreclass AudienceLiveListActivity : AppCompatActivity() {companion object {private const val TAG = "AudienceLiveListActivity"private const val FETCH_COUNT = 6const val EXTRA_LIVE_ID = "liveID"}private lateinit var liveListView: LiveListViewprivate var isLoading = falseoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val liveID = intent.getStringExtra(EXTRA_LIVE_ID).orEmpty()// 1. Create LiveListView. The liveID passed in the constructor will be the first live room shown.// Override onLoadMore to load more data when the audience swipes near the end of the list.liveListView = object : LiveListView(this, liveID = liveID) {override fun onLoadMore() {loadMore()}}// 2. Add LiveListView to the UIsetContentView(liveListView)// 3. Fetch the initial live room list and set it to LiveListViewrefresh()}private fun refresh() {if (isLoading) returnfetch(isRefresh = true, callback = object : CompletionHandler {override fun onSuccess() {liveListView.setData(LiveListStore.shared().liveState.liveList.value)isLoading = false}override fun onFailure(code: Int, desc: String) {Log.e(TAG, "refresh failed, code:$code, desc:$desc")isLoading = false}})}private fun loadMore() {if (isLoading) returnval cursor = LiveListStore.shared().liveState.liveListCursor.valueif (cursor.isEmpty()) returnval oldSize = LiveListStore.shared().liveState.liveList.value.sizefetch(isRefresh = false, callback = object : CompletionHandler {override fun onSuccess() {val newList = LiveListStore.shared().liveState.liveList.valueif (newList.size > oldSize) {liveListView.appendData(newList.subList(oldSize, newList.size))}isLoading = false}override fun onFailure(code: Int, desc: String) {Log.e(TAG, "loadMore failed, code:$code, desc:$desc")isLoading = false}})}private fun fetch(isRefresh: Boolean, callback: CompletionHandler) {isLoading = trueval cursor = LiveListStore.shared().liveState.liveListCursor.valueval fetchCursor = if (isRefresh || cursor.isEmpty()) "" else cursorLiveListStore.shared().fetchLiveList(fetchCursor, FETCH_COUNT, object : CompletionHandler {override fun onSuccess() {callback.onSuccess()}override fun onFailure(code: Int, desc: String) {callback.onFailure(code, desc)}})}}
// Navigate to the "Swipe to Switch Live Room" viewing pagefun enterLiveListPage(context: Context, liveID: String) {val intent = Intent(context, AudienceLiveListActivity::class.java)intent.putExtra(AudienceLiveListActivity.EXTRA_LIVE_ID, liveID)context.startActivity(intent)}
Method / Property | Description |
LiveListView(context, liveID) | Constructor. The liveID will be the first live room (pinned to the top of the list). If not provided, the first item in the list is shown. |
setData(liveList: List) | Sets the live room list data. Duplicates are removed by liveID, and the liveID passed in the constructor is pinned to the top. |
appendData(liveList: List) | Appends live room data to the end of the list for paginated loading. Existing live rooms are updated rather than inserted repeatedly. |
onLoadMore() | Overridable method. When the audience swipes to within two live rooms from the end of the list, this callback is triggered to load the next page of data. |
Capability | API |
Fetch List | LiveListStore.shared().fetchLiveList(cursor, count, CompletionHandler) |
List Data | LiveListStore.shared().liveState.liveList.value |
Pagination Cursor | LiveListStore.shared().liveState.liveListCursor.value (empty means no more data) |
Feature | Description | Integration Guide |
Audience Viewing | Use PlayerView to watch a single live room, including stream pulling, Enter Room, and interactive features. | |
Host Streaming | Full host streaming workflow, including pre-stream preparation and post-stream interactions. | |
Gift System | Implement custom gift asset configuration, billing system integration, PK scenario interaction, and more. |
피드백