mod: 直播弹幕开关

This commit is contained in:
guozhigq
2024-08-23 23:47:15 +08:00
parent ddaf258062
commit 05361c7fdd
3 changed files with 105 additions and 55 deletions

View File

@ -129,7 +129,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
// double initDuration = box.maxWidth / 12;
return Obx(
() => AnimatedOpacity(
opacity: playerController.isOpenDanmu.value ? 1 : 1,
opacity: playerController.isOpenDanmu.value ? 1 : 0,
duration: const Duration(milliseconds: 100),
child: DanmakuView(
createdController: (DanmakuController e) async {

View File

@ -45,6 +45,8 @@ class LiveRoomController extends GetxController {
TextEditingController inputController = TextEditingController();
// 加入直播间提示
RxMap<String, String> joinRoomTip = {'userName': '', 'message': ''}.obs;
// 直播间弹幕开关 默认打开
RxBool danmakuSwitch = true.obs;
@override
void onInit() {
@ -69,6 +71,9 @@ class LiveRoomController extends GetxController {
userId = userInfo.mid;
}
liveDanmakuInfo().then((value) => initSocket());
danmakuSwitch.listen((p0) {
plPlayerController.isOpenDanmu.value = p0;
});
}
playerInit(source) async {
@ -87,6 +92,7 @@ class LiveRoomController extends GetxController {
enableHA: true,
autoplay: true,
);
plPlayerController.isOpenDanmu.value = danmakuSwitch.value;
}
Future queryLiveInfo() async {
@ -185,6 +191,7 @@ class LiveRoomController extends GetxController {
} else if (liveMsg.first.type == LiveMessageType.join ||
liveMsg.first.type == LiveMessageType.follow) {
// 每隔一秒依次liveMsg中的每一项赋给activeUserName
int index = 0;
Timer.periodic(const Duration(seconds: 2), (timer) {
if (index < liveMsg.length) {
@ -200,6 +207,7 @@ class LiveRoomController extends GetxController {
timer.cancel();
}
});
return;
}
// 过滤出聊天消息
@ -223,8 +231,10 @@ class LiveRoomController extends GetxController {
}).toList();
// 添加到 danmakuController
if (danmakuSwitch.value) {
danmakuController?.addItems(danmakuItems);
}
}
},
onErrorCb: (e) {
print('error: $e');

View File

@ -325,7 +325,33 @@ class _LiveRoomPageState extends State<LiveRoomPage>
),
child: Row(
children: [
const SizedBox(width: 4),
SizedBox(
width: 34,
height: 34,
child: Obx(
() => IconButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
backgroundColor: MaterialStateProperty.resolveWith(
(Set<MaterialState> states) {
return Colors.grey.withOpacity(0.1);
}),
),
onPressed: () {
_liveRoomController.danmakuSwitch.value =
!_liveRoomController.danmakuSwitch.value;
},
icon: Icon(
_liveRoomController.danmakuSwitch.value
? Icons.subtitles_outlined
: Icons.subtitles_off_outlined,
size: 19,
color: Colors.white,
),
),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: _liveRoomController.inputController,
@ -340,11 +366,19 @@ class _LiveRoomPageState extends State<LiveRoomPage>
),
),
),
IconButton(
SizedBox(
width: 34,
height: 34,
child: IconButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () => _liveRoomController.sendMsg(),
icon: const Icon(
Icons.send,
color: Colors.white,
size: 20,
),
),
),
],
@ -418,6 +452,11 @@ Widget buildMessageListUI(
).createShader(bounds);
},
blendMode: BlendMode.dstIn,
child: GestureDetector(
onTap: () {
// 键盘失去焦点
FocusScope.of(context).requestFocus(FocusNode());
},
child: ListView.builder(
controller: scrollController,
itemCount: liveRoomController.messageList.length,
@ -472,6 +511,7 @@ Widget buildMessageListUI(
),
),
),
),
);
}