Skip to content

Commit e89588a

Browse files
committed
支持设置播放器中SC显示隐藏
1 parent bc9777d commit e89588a

File tree

5 files changed

+78
-18
lines changed

5 files changed

+78
-18
lines changed

simple_live_app/lib/app/controller/app_settings_controller.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,17 @@ class AppSettingsController extends GetxController {
126126

127127
audioOutputDriver.value = LocalStorageService.instance.getValue(
128128
LocalStorageService.kAudioOutputDriver,
129-
Platform.isAndroid ? "audiotrack" : Platform.isLinux ? "pulse" : Platform.isWindows ? "wasapi" : Platform.isIOS ? "audiounit" : Platform.isMacOS ? "coreaudio" : "sdl",
129+
Platform.isAndroid
130+
? "audiotrack"
131+
: Platform.isLinux
132+
? "pulse"
133+
: Platform.isWindows
134+
? "wasapi"
135+
: Platform.isIOS
136+
? "audiounit"
137+
: Platform.isMacOS
138+
? "coreaudio"
139+
: "sdl",
130140
);
131141

132142
videoHardwareDecoder.value = LocalStorageService.instance.getValue(
@@ -370,6 +380,13 @@ class AppSettingsController extends GetxController {
370380
.setValue(LocalStorageService.kAutoFullScreen, e);
371381
}
372382

383+
var playershowSuperChat = true.obs;
384+
void setPlayerShowSuperChat(bool e) {
385+
playershowSuperChat.value = e;
386+
LocalStorageService.instance
387+
.setValue(LocalStorageService.kPlayerShowSuperChat, e);
388+
}
389+
373390
RxSet<String> shieldList = <String>{}.obs;
374391
void addShieldList(String e) {
375392
shieldList.add(e);

simple_live_app/lib/modules/live_room/live_room_page.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,17 @@ class LiveRoomPage extends GetView<LiveRoomController> {
676676
},
677677
),
678678
),
679+
AppStyle.divider,
680+
Obx(
681+
() => SettingsSwitch(
682+
title: "播放器中显示SC",
683+
value:
684+
AppSettingsController.instance.playershowSuperChat.value,
685+
onChanged: (e) {
686+
AppSettingsController.instance.setPlayerShowSuperChat(e);
687+
},
688+
),
689+
),
679690
],
680691
),
681692
),

simple_live_app/lib/modules/live_room/player/player_controls.dart

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ Widget buildFullControls(
5151
buildDanmuView(videoState, controller),
5252

5353
// 左下角SC显示
54-
Visibility(
55-
visible: (!Platform.isAndroid && !Platform.isIOS) || controller.fullScreenState.value,
56-
child: Positioned(
57-
left: 24,
58-
bottom: 24,
59-
child: PlayerSuperChatOverlay(controller: controller),
54+
Obx(
55+
() => Visibility(
56+
visible: AppSettingsController.instance.playershowSuperChat.value &&
57+
((!Platform.isAndroid && !Platform.isIOS) ||
58+
controller.fullScreenState.value),
59+
child: Positioned(
60+
left: 24,
61+
bottom: 24,
62+
child: PlayerSuperChatOverlay(controller: controller),
63+
),
6064
),
6165
),
6266

@@ -286,7 +290,8 @@ Widget buildFullControls(
286290
padding: const EdgeInsets.only(left: 8.0),
287291
child: Text(
288292
controller.liveDuration.value,
289-
style: const TextStyle(fontSize: 14, color: Colors.white),
293+
style:
294+
const TextStyle(fontSize: 14, color: Colors.white),
290295
),
291296
),
292297
),
@@ -432,12 +437,16 @@ Widget buildControls(
432437
buildDanmuView(videoState, controller),
433438

434439
// 左下角SC显示
435-
Visibility(
436-
visible: (!Platform.isAndroid && !Platform.isIOS) || controller.fullScreenState.value,
437-
child: Positioned(
438-
left: 24,
439-
bottom: 24,
440-
child: PlayerSuperChatOverlay(controller: controller),
440+
Obx(
441+
() => Visibility(
442+
visible: AppSettingsController.instance.playershowSuperChat.value &&
443+
((!Platform.isAndroid && !Platform.isIOS) ||
444+
controller.fullScreenState.value),
445+
child: Positioned(
446+
left: 24,
447+
bottom: 24,
448+
child: PlayerSuperChatOverlay(controller: controller),
449+
),
441450
),
442451
),
443452

@@ -907,7 +916,12 @@ class PlayerSuperChatCard extends StatefulWidget {
907916
final LiveSuperChatMessage message;
908917
final VoidCallback onExpire;
909918
final int duration;
910-
const PlayerSuperChatCard({required this.message, required this.onExpire, required this.duration, Key? key}) : super(key: key);
919+
const PlayerSuperChatCard(
920+
{required this.message,
921+
required this.onExpire,
922+
required this.duration,
923+
Key? key})
924+
: super(key: key);
911925
@override
912926
State<PlayerSuperChatCard> createState() => _PlayerSuperChatCardState();
913927
}
@@ -930,11 +944,13 @@ class _PlayerSuperChatCardState extends State<PlayerSuperChatCard> {
930944
});
931945
});
932946
}
947+
933948
@override
934949
void dispose() {
935950
timer.cancel();
936951
super.dispose();
937952
}
953+
938954
@override
939955
Widget build(BuildContext context) {
940956
return Opacity(
@@ -957,7 +973,8 @@ class LocalDisplaySC {
957973

958974
class PlayerSuperChatOverlay extends StatefulWidget {
959975
final LiveRoomController controller;
960-
const PlayerSuperChatOverlay({required this.controller, Key? key}) : super(key: key);
976+
const PlayerSuperChatOverlay({required this.controller, Key? key})
977+
: super(key: key);
961978
@override
962979
State<PlayerSuperChatOverlay> createState() => _PlayerSuperChatOverlayState();
963980
}
@@ -994,7 +1011,8 @@ class _PlayerSuperChatOverlayState extends State<PlayerSuperChatOverlay> {
9941011
}
9951012
}
9961013
// 监听SC列表变化
997-
_worker = ever<List<LiveSuperChatMessage>>(widget.controller.superChats, (list) {
1014+
_worker =
1015+
ever<List<LiveSuperChatMessage>>(widget.controller.superChats, (list) {
9981016
// 新增
9991017
for (var sc in list) {
10001018
if (!_displayed.any((e) => e.sc == sc)) {
@@ -1018,7 +1036,8 @@ class _PlayerSuperChatOverlayState extends State<PlayerSuperChatOverlay> {
10181036

10191037
@override
10201038
Widget build(BuildContext context) {
1021-
final sorted = _displayed.toList()..sort((a, b) => a.sc.endTime.compareTo(b.sc.endTime));
1039+
final sorted = _displayed.toList()
1040+
..sort((a, b) => a.sc.endTime.compareTo(b.sc.endTime));
10221041
return Column(
10231042
crossAxisAlignment: CrossAxisAlignment.start,
10241043
children: [

simple_live_app/lib/modules/settings/play_settings_page.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ class PlaySettingsPage extends GetView<AppSettingsController> {
145145
),
146146
),
147147
),
148+
AppStyle.divider,
149+
Obx(
150+
() => SettingsSwitch(
151+
title: "播放器中显示SC",
152+
value: controller.playershowSuperChat.value,
153+
onChanged: (e) {
154+
controller.setPlayerShowSuperChat(e);
155+
},
156+
),
157+
),
148158
],
149159
),
150160
),

simple_live_app/lib/services/local_storage_service.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class LocalStorageService extends GetxService {
105105
/// 自动全屏
106106
static const String kAutoFullScreen = "AutoFullScreen";
107107

108+
/// 显示SC
109+
static const String kPlayerShowSuperChat = "PlayerShowSuperChat";
110+
108111
/// 播放器音量
109112
static const String kPlayerVolume = "PlayerVolume";
110113

0 commit comments

Comments
 (0)