TUILiveKit live comment system delivers a robust interactive solution for live streaming, designed to boost engagement and entertainment for both hosts and audiences. This guide helps you quickly implement live comment features in your streaming rooms, with extensive customization options to fit your business needs.Live Comment Sending Component (BarrageInputView) | Live Comment Display Component (BarrageStreamView) |
![]() | ![]() |
Component Name | Description |
Live Comment Display Component (BarrageStreamView) | Handles real-time rendering and management of live comments, offering comprehensive support for message list rendering, time aggregation, user interaction, and adaptive layouts. |
Live Comment Sending Component (BarrageInputView) | Provides an input interface with rich text editing and message sending features, including emoji picker, character limit, and state management for a seamless input experience. |
BarrageInputView and add it to your view:// 1. Create BarrageInputView objectval barrageInputView = BarrageInputView(context)// 2. Initialize BarrageInputView; liveId is the room ID of the current live streambarrageInputView.init("your liveId")// 3. Add BarrageInputView to your viewyourBarrageInputContainerView.addView(barrageInputView)
TUILiveKit does not include full emoji asset packs. Before launching commercially, replace the default emojis with your own designs or packs you have rights to use. The default yellow face emoji pack shown below is owned by TRTC and available for commercial licensing. For authorization, submit a ticket to contact us.
BarrageStreamView and add it to your view:// 1. Create BarrageStreamView objectval barrageStreamView = BarrageStreamView(context)// 2. Initialize BarrageStreamView; liveId is the current live stream's room ID, ownerId is the host's userId, used to distinguish display effects between host and audiencebarrageStreamView.init("your liveId", "your ownerId")// 3. Add BarrageStreamView to your viewyourBarrageContainerView.addView(barrageStreamView)
BarrageStreamView supports inserting messages that are visible only on the local client, typically for system notifications, welcome messages, or operation feedback. Use the following code to insert and display a text message locally:import io.trtc.tuikit.atomicxcore.api.barrage.Barrage// 1. Create Barrage objectval barrage = Barrage()// 2. Set Barrage message content; customize your message as neededbarrage.textContent = "your barrage context"barrage.sender.userID = "your sender userId"barrage.sender.userName = "your sender userName"barrage.sender.avatarURL = "your sender avatarURL"// 3. Insert the created live comment message into the local display componentbarrageStreamView.insertBarrages(barrage)
TUILiveKit live comment system offers flexible style customization. You can control display effects based on business tags attached to each message. This section covers two scenarios: modifying default live comment styles and customizing styles for locally inserted messages.
BarrageItemAdapter and define your custom layout and data binding logic.class YourBarrageAdapter(private val context: Context) : BarrageItemAdapter {override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {// Customize UI view for your business requirementsval view = LayoutInflater.from(parent.context).inflate(R.layout.item_barrage_your_custom, parent, false)return YourViewHolder(view)}override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, barrage: Barrage) {(holder as? YourViewHolder)?.bind(barrage)}private inner class YourViewHolder(view: View) :RecyclerView.ViewHolder(view) {fun bind(barrage: Barrage) {// Bind data}}}
BarrageStreamView. TUILiveKit defines built-in types: type 0 for regular text messages, type 1 for gift messages.// Override default text live comment (type 0)barrageStreamView.setItemAdapter(0, YourBarrageAdapter())// Override default gift live comment (type 1)barrageStreamView.setItemAdapter(1, YourGiftBarrageAdapter())
type = "system_notice").import io.trtc.tuikit.atomicxcore.api.barrage.Barrageprivate fun insertSystemWelcome() {val barrage = Barrage()barrage.textContent = "Welcome to the live room. Please communicate respectfully."// Set a business identifier for UI recognitionval extInfo = HashMap<String, String>()extInfo["type"] = "system_notice"barrage.extensionInfo = extInfo// Insert directly via UI component interface; no remote sending involvedbarrageStreamView.insertBarrages(barrage)}
BarrageItemTypeDelegate interface to return a custom style ID based on the tag (e.g., type 100 as your custom style ID).class YourBarrageTypeDelegate : BarrageItemTypeDelegate {override fun getItemType(position: Int, barrage: Barrage): Int {val type = barrage.extensionInfo?.get("type")return when (type) {"system_notice" -> 100 // Custom style IDelse -> 0 // Default to regular text live comment}}}
YourSystemNoticeAdapter to render messages with ItemType 100.// 1. Define adapterclass YourSystemNoticeAdapter : BarrageItemAdapter {override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {val view = LayoutInflater.from(parent.context).inflate(R.layout.item_barrage_system_notice, parent, false)return SystemNoticeViewHolder(view)}override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, barrage: Barrage) {(holder as? SystemNoticeViewHolder)?.bind(barrage)}private inner class SystemNoticeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {fun bind(barrage: Barrage) {// Render custom view logic}}}// 2. Bind to componentbarrageStreamView.setItemTypeDelegate(YourBarrageTypeDelegate())barrageStreamView.setItemAdapter(100, YourSystemNoticeAdapter())
sender.userID field in the Barrage message to check whether the sender is the host. Adjust your display logic accordingly.setItemTypeDelegate and setItemAdapter after initializing BarrageStreamView.getItemType matches the ID registered with the adapter.extensionInfo.フィードバック