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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user