Message Sending Component. Our message rendering component will then render the received messages on the screen, thereby enhancing the fun of the live stream and making the interaction experience more enjoyable and vivid.BarrageStreamView: A rendering component that displays barrage messages on the screen.BarrageStreamView: A message rendering component that displays barrage messages on the screen.BarrageDisplayWidget: A rendering component that displays barrage messages on the screen.

settings.gradle.kts (or settings.gradle) file in the project root directory: add the jitpack repository dependency (to download the SVGAPlayer third-party library for playing gift svg animations).dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()// Add jitpack repository urlmaven { url = uri("https://jitpack.io") }}}
dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()// Add jitpack repository urlmaven { url 'https://jitpack.io' }}}
settings.gradle.kts (or settings.gradle) file in the project root directory. It enables importing the downloaded tuilivekit component into your current project:include(":tuilivekit")
include ':tuilivekit'
build.gradle.kts (or build.gradle) file under the app directory and add the following code in it. It enables declaring the current app's dependency on the newly joined tuilivekit component:api(project(":tuilivekit"))
api project(':tuilivekit')
TRTC SDK, IM SDK, tuiroomengine, and the public library tuicore by default. Developers do not need to separately configure them. If needed, just modify the tuilivekit/build.gradle file to upgrade.proguard-rules.pro file:-keep class com.tencent.** { *; }-keep class com.trtc.uikit.livekit.livestreamcore.** { *; }-keep class com.trtc.uikit.livekit.component.gift.store.model.** { *; }-keep class com.squareup.wire.** { *; }-keep class com.opensource.svgaplayer.proto.** { *; }-keep class com.tcmediax.** { *; }-keep class com.tencent.** { *; }-keep class com.tencent.xmagic.** { *; }-keep class androidx.exifinterface.** {*;}-keep class com.google.gson.** { *;}# Tencent Effect SDK - beauty-keep class com.tencent.xmagic.** { *;}-keep class org.light.** { *;}-keep class org.libpag.** { *;}-keep class org.extra.** { *;}-keep class com.gyailib.**{ *;}-keep class com.tencent.cloud.iai.lib.** { *;}-keep class com.tencent.beacon.** { *;}-keep class com.tencent.qimei.** { *;}-keep class androidx.exifinterface.** { *;}
AndroidManifest.xml file under the app directory, add tools:replace="android:allowBackup" and android:allowBackup="false" in the application node, overwrite the setting within component, and use your own setting.// app/src/main/AndroidManifest.xml<application...// add the following configuration to overwrite the configuration in the dependent sdkandroid:allowBackup="false"tools:replace="android:allowBackup">
Barrage folder from GitHub to your local system.
pod 'TUIBarrage' dependency in the Podfile file of your project.target 'xxxx' do......pod 'TUIBarrage', :path => '../Component/Barrage/TUIBarrage.podspec'// The path is the relative path between your Podfile file and TUIBarrage.Podspec file.end
Podfile file, first use the terminal to cd into the xxxx.xcodeproj directory, then create it with the following command:pod init
cd to the Podfile directory, then execute the following commands to install components.pod install
dependencies:flutter:sdk: flutterflutter_localizations:sdk: flutterintl: ^0.19.0# Add barrage dependencylive_uikit_barrage: ^1.0.0
flutter pub get command.localizationsDelegates and supportedLocales properties of your application's MaterialApp.MaterialApp(localizationsDelegates: const [...BarrageLocalizations.localizationsDelegates,], supportedLocales: const [...BarrageLocalizations.supportedLocales,],// ...);
BarrageStreamView to display barrage messages:BarrageStreamView barrageStreamView = new BarrageStreamView(mContext);// ownerId indicates the room owner's ID, used to distinguish display effects between host and viewersbarrageStreamView.init(roomId, ownerId);mLayoutBarrageContainer.addView(barrageStreamView);
BarrageStreamView to display barrage messages:import TUIBarragelet barrageDisplayView =BarrageStreamView(roomId: roomId)// ...Add barrageInputView to your parent view here and adjust the layout
barrageDisplayView.setOwnerId(ownerId)
BarrageDisplayController _displayController = BarrageDisplayController(roomId: "liveRoomId", /// Replace with your live stream room IDownerId: "liveOwnerId", /// Replace with your live stream host IDselfUserId: "selfUserId", /// Replace with your currently logged-in user IDselfName: "selfUserName"; /// Replace with your currently logged-in user nicknameBarrageDisplayWidget(controller: _displayController);
insertBarrages API method for batch inserting custom messages (such as gift messages, live room notices). Usually, custom messages combined with custom styles can achieve different display effects.// Insert a gift message into the barrage areaBarrage barrage = new Barrage();barrage.content = "gift";barrage.user.userId = "sender.userId";barrage.user.userName = "sender.userName";barrage.user.avatarUrl = "sender.avatarUrl";barrage.extInfo.put("GIFT_VIEW_TYPE", "GIFT_VIEW_TYPE_1");barrage.extInfo.put("GIFT_NAME", "giftName");barrage.extInfo.put("GIFT_COUNT", "giftCount");barrage.extInfo.put("GIFT_ICON_URL", "imageUrl");barrage.extInfo.put("GIFT_RECEIVER_USERNAME"," receiver.userName");barrageStreamView.insertBarrages(barrage);
Map for storing custom data.insertBarrages API method for batch inserting custom messages (such as gift messages, live room notices). Usually, custom messages combined with custom styles can achieve different display effects.import TUIBarrageimport RTCCommon// Example 1: Insert a gift message into the barrage arealet barrage = TUIBarrage()barrage.content = "gift"barrage.user.userId = "sender.userId"barrage.user.userName = "sender.userName"barrage.user.avatarUrl = "sender.avatarUrl"barrage.user.level = "sender.level"let giftCount = 1barrage.extInfo["TYPE"] = AnyCodable("GIFTMESSAGE")barrage.extInfo["gift_name"] = AnyCodable("gift.giftName")barrage.extInfo["gift_count"] = AnyCodable(giftCount)barrage.extInfo["gift_icon_url"] = AnyCodable("gift.imageUrl")barrage.extInfo["gift_receiver_username"] = AnyCodable("receiver.userName")barrageDisplayView.insertBarrages([barrage])
Map for storing custom data.BarrageUser barrageUser = BarrageUser();barrageUser.userId = "enterRoomUserId"; /// Displayed user ID informationbarrageUser.userName = "enterRoomUserName"; /// Displayed user nickname informationbarrageUser.avatarUrl = "enterRoomUserAvatar"; /// Displayed user avatar informationbarrageUser.level = "66"; /// Displayed user level informationBarrage barrage = Barrage();barrage.user = barrageUser;barrage.content = "Enter a room"; /// Displayed text content_displayController.insertMessage(barrage);
public static final int GIFT_VIEW_TYPE_1 = 1;public class BarrageViewTypeDelegate implements BarrageItemTypeDelegate {@Overridepublic int getItemType(int position, Barrage barrage) {if (barrage.extInfo != null && barrage.extInfo.containsKey("GIFT_VIEW_TYPE")) {String viewTypeString = String.valueOf(barrage.extInfo.get("GIFT_VIEW_TYPE"));if (String.valueOf(GIFT_VIEW_TYPE_1).equals(viewTypeString)) {return GIFT_VIEW_TYPE_1;}}return 0;}}mBarrageStreamView.setItemTypeDelegate(new BarrageViewTypeDelegate());
public class GiftBarrageAdapter implements BarrageItemAdapter {@Overridepublic RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {LinearLayout ll = new LinearLayout(mContext);ll.addView(new TextView(mContext));return new GiftViewHolder(ll, mDefaultGiftIcon);}@Overridepublic void onBindViewHolder(RecyclerView.ViewHolder holder, int position, Barrage barrage) {GiftViewHolder viewHolder = (GiftViewHolder) holder;viewHolder.bind(barrage);}// GiftViewHolder...}mBarrageStreamView.setItemAdapter(GIFT_VIEW_TYPE_1, new GiftBarrageAdapter(mContext));
import TUIBarrageclass MyViewController: BarrageStreamViewDelegate {let barrageDisplayView = BarrageStreamView(roomId: roomId)override func viewDidLoad() {super.viewDidLoad()barrageDisplayView.delegate = self // Set the proxy for BarrageStreamView// ...}func onBarrageClicked(user: TUIUserInfo) {// Here you can add the event processing logic for barrage message clicks. 'user' is the sender information.}func barrageDisplayView(_ barrageDisplayView: BarrageStreamView, createCustomCell barrage: TUIBarrage) -> UIView? {// Whether to use Custom UI, if not needed, return nil justguard let type = barrage.extInfo["TYPE"], type.value as? String == "GIFTMESSAGE" else {return nil}// Return custom message style UI (gift echo)return CustomBarrageView(barrage: barrage)}}// Custom UIclass CustomBarrageView: UIView {let barrage: TUIBarrageinit(barrage: TUIBarrage) {self.barrage = barragesuper.init(frame: .zero)}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}// ...Layout and draw your own UI here}
/// 1. Define a custom barrage item builderclass GiftBarrageItemBuilder extends CustomBarrageBuilder {@overrideWidget buildWidget(BuildContext context, Barrage barrage) { /// When shouldCustomizeBarrageItem returns true, customize widgetreturn const Text(barrage.content,style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.red),);}@overridebool shouldCustomizeBarrageItem(Barrage barrage) { /// For the data model of the barrage message, determine whether the current barrage message needs to be customizedif (barrage.extInfo.keys.isNotEmpty) {return true;}return false;}}/// 2. Set setCustomBarrageBuilder for BarrageDisplayWidget_displayController.setCustomBarrageBuilder(GiftBarrageItemBuilder());
Feedback