mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: danmaku showing
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -3,7 +3,8 @@ import 'package:PiliPalaX/models/danmaku/dm.pb.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PlDanmakuController {
|
||||
PlDanmakuController(this.cid, this.danmakuWeightNotifier, this.danmakuFilterNotifier);
|
||||
PlDanmakuController(
|
||||
this.cid, this.danmakuWeightNotifier, this.danmakuFilterNotifier);
|
||||
final int cid;
|
||||
final ValueNotifier<int> danmakuWeightNotifier;
|
||||
final ValueNotifier<List<Map<String, dynamic>>> danmakuFilterNotifier;
|
||||
@@ -27,7 +28,8 @@ class PlDanmakuController {
|
||||
danmakuWeight = danmakuWeightNotifier.value;
|
||||
});
|
||||
danmakuFilterNotifier.addListener(() {
|
||||
print("danmakuFilter changed from $danmakuFilter to ${danmakuFilterNotifier.value}");
|
||||
print(
|
||||
"danmakuFilter changed from $danmakuFilter to ${danmakuFilterNotifier.value}");
|
||||
danmakuFilter = danmakuFilterNotifier.value;
|
||||
});
|
||||
if (requestedSeg.isEmpty) {
|
||||
|
||||
@@ -23,7 +23,7 @@ class PlDanmaku extends StatefulWidget {
|
||||
State<PlDanmaku> createState() => _PlDanmakuState();
|
||||
}
|
||||
|
||||
class _PlDanmakuState extends State<PlDanmaku> {
|
||||
class _PlDanmakuState extends State<PlDanmaku> with WidgetsBindingObserver {
|
||||
late PlPlayerController playerController;
|
||||
late PlDanmakuController _plDanmakuController;
|
||||
DanmakuController? _controller;
|
||||
@@ -38,10 +38,22 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
late double strokeWidth;
|
||||
late int fontWeight;
|
||||
int latestAddedPosition = -1;
|
||||
bool showDanmaku = true;
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
showDanmaku = true;
|
||||
} else if (state == AppLifecycleState.paused) {
|
||||
showDanmaku = false;
|
||||
playerController.danmakuController?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
enableShowDanmaku =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: true);
|
||||
_plDanmakuController = PlDanmakuController(
|
||||
@@ -100,7 +112,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
List<DanmakuElem>? currentDanmakuList =
|
||||
_plDanmakuController.getCurrentDanmaku(currentPosition);
|
||||
|
||||
if (currentDanmakuList != null && _controller != null) {
|
||||
if (showDanmaku && currentDanmakuList != null && _controller != null) {
|
||||
Color? defaultColor = playerController.blockTypes.contains(6)
|
||||
? DmUtils.decimalToColor(16777215)
|
||||
: null;
|
||||
@@ -118,6 +130,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
playerController.removePositionListener(videoPositionListen);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ class LiveRoomController extends GetxController {
|
||||
RxBool disableAutoScroll = false.obs;
|
||||
double? brightness;
|
||||
DanmakuController? controller;
|
||||
bool showDanmaku = true;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -135,17 +136,19 @@ class LiveRoomController extends GetxController {
|
||||
// logger.i(' 原始弹幕消息 ======> ${jsonEncode(obj)}');
|
||||
messages.add(obj);
|
||||
Map json = jsonDecode(obj['info'][0][15]['extra']);
|
||||
controller?.addItems([
|
||||
DanmakuItem(
|
||||
json['content'],
|
||||
color: DmUtils.decimalToColor(json['color']),
|
||||
// time: e.progress,
|
||||
type: DmUtils.getPosition(json['mode']),
|
||||
)
|
||||
]);
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => scrollToBottom(),
|
||||
);
|
||||
if (showDanmaku) {
|
||||
controller?.addItems([
|
||||
DanmakuItem(
|
||||
json['content'],
|
||||
color: DmUtils.decimalToColor(json['color']),
|
||||
// time: e.progress,
|
||||
type: DmUtils.getPosition(json['mode']),
|
||||
)
|
||||
]);
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => scrollToBottom(),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
msgStream?.init();
|
||||
|
||||
@@ -25,7 +25,8 @@ class LiveRoomPage extends StatefulWidget {
|
||||
State<LiveRoomPage> createState() => _LiveRoomPageState();
|
||||
}
|
||||
|
||||
class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
class _LiveRoomPageState extends State<LiveRoomPage>
|
||||
with WidgetsBindingObserver {
|
||||
late final int _roomId;
|
||||
final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
|
||||
late final PlPlayerController plPlayerController;
|
||||
@@ -57,6 +58,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
_roomId = int.parse(Get.parameters['roomid'] ?? '-1');
|
||||
PlPlayerController.setPlayCallBack(playCallBack);
|
||||
if (Platform.isAndroid) {
|
||||
@@ -82,6 +84,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
ScreenBrightness().resetApplicationScreenBrightness();
|
||||
PlPlayerController.setPlayCallBack(null);
|
||||
floating?.dispose();
|
||||
@@ -94,6 +97,16 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_liveRoomController.showDanmaku = true;
|
||||
} else if (state == AppLifecycleState.paused) {
|
||||
_liveRoomController.showDanmaku = false;
|
||||
plPlayerController.danmakuController?.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget videoPlayerPanel = FutureBuilder(
|
||||
|
||||
Reference in New Issue
Block a user