From a49c400a8ea8cf213e30bd8c6f52317feae5ec48 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Wed, 30 Aug 2023 23:44:09 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E8=AE=BE=E7=BD=AE=E5=BC=B9=E5=B9=95?= =?UTF-8?q?=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/danmaku/view.dart | 26 +++++++++++++++++++++++--- lib/pages/setting/play_setting.dart | 6 ++++++ lib/plugin/pl_player/controller.dart | 4 +++- lib/utils/storage.dart | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/pages/danmaku/view.dart b/lib/pages/danmaku/view.dart index 89885ee9..972c96c3 100644 --- a/lib/pages/danmaku/view.dart +++ b/lib/pages/danmaku/view.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; import 'package:ns_danmaku/ns_danmaku.dart'; import 'package:pilipala/pages/danmaku/index.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/utils/danmaku.dart'; +import 'package:pilipala/utils/storage.dart'; /// 传入播放器控制器,监听播放进度,加载对应弹幕 class PlDanmaku extends StatefulWidget { @@ -25,22 +27,37 @@ class _PlDanmakuState extends State { late PlDanmakuController _plDanmakuController; DanmakuController? _controller; bool danmuPlayStatus = true; + Box setting = GStrorage.setting; + late bool enableShowDanmaku; @override void initState() { super.initState(); + enableShowDanmaku = + setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false); _plDanmakuController = PlDanmakuController(widget.cid, widget.playerController); if (mounted) { playerController = widget.playerController; _plDanmakuController.videoDuration = playerController.duration.value; - _plDanmakuController - ..calcSegment() - ..queryDanmaku(); + if (enableShowDanmaku || playerController.isOpenDanmu.value) { + _plDanmakuController + ..calcSegment() + ..queryDanmaku(); + } playerController ..addStatusLister(playerListener) ..addPositionListener(videoPositionListen); } + playerController.isOpenDanmu.listen((p0) { + if (p0) { + if (_plDanmakuController.dmSegList.isEmpty) { + _plDanmakuController + ..calcSegment() + ..queryDanmaku(); + } + } + }); } // 播放器状态监听 @@ -61,6 +78,9 @@ class _PlDanmakuState extends State { PlDanmakuController ctr = _plDanmakuController; int currentPosition = position.inMilliseconds; + if (!playerController.isOpenDanmu.value) { + return; + } // 超出分段数返回 if (ctr.currentSegIndex >= ctr.dmSegList.length) { return; diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index 231c2dba..a1842e57 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -108,6 +108,12 @@ class _PlaySettingState extends State { setKey: SettingBoxKey.enableQuickDouble, defaultVal: true, ), + const SetSwitchItem( + title: '弹幕开关', + subTitle: '展示弹幕', + setKey: SettingBoxKey.enableShowDanmaku, + defaultVal: false, + ), ListTile( dense: false, title: Text('默认画质', style: titleStyle), diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 6009b481..fe63cc3d 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -196,13 +196,15 @@ class PlPlayerController { Rx get videoType => _videoType; /// 弹幕开关 - Rx isOpenDanmu = true.obs; + Rx isOpenDanmu = false.obs; // 关联弹幕控制器 DanmakuController? danmakuController; // 添加一个私有构造函数 PlPlayerController._() { _videoType = videoType; + isOpenDanmu.value = + setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false); // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // if (status == PlayerStatus.playing) { // WakelockPlus.enable(); diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index de7ffd04..87c226a6 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -101,6 +101,7 @@ class SettingBoxKey { static const String enableAutoExit = 'enableAutoExit'; // youtube 双击快进快退 static const String enableQuickDouble = 'enableQuickDouble'; + static const String enableShowDanmaku = 'enableShowDanmaku'; /// 隐私 static const String blackMidsList = 'blackMidsList';