From 8bc6a32b0619ef8796c098c124500a29c44654cc Mon Sep 17 00:00:00 2001 From: guozhigq Date: Fri, 25 Aug 2023 23:51:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=92=AD=E6=94=BE=E5=99=A8=E4=BA=AE?= =?UTF-8?q?=E5=BA=A6=E8=AE=B0=E5=BF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/setting/play_setting.dart | 6 +++++ lib/pages/video/detail/controller.dart | 9 +++++++ lib/pages/video/detail/view.dart | 5 ++++ lib/plugin/pl_player/controller.dart | 35 +++++++++++++------------- lib/plugin/pl_player/view.dart | 1 + lib/utils/storage.dart | 1 + 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index 77f6f269..8f9d8226 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -72,6 +72,12 @@ class _PlaySettingState extends State { setKey: SettingBoxKey.enableOnlineTotal, defaultVal: false, ), + const SetSwitchItem( + title: '亮度记忆', + subTitle: '返回时自动调整视频亮度', + setKey: SettingBoxKey.enableAutoBrightness, + defaultVal: false, + ), ListTile( dense: false, title: Text('默认画质', style: titleStyle), diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index a7ea10f4..3f4bfc6f 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -14,6 +14,7 @@ import 'package:pilipala/pages/video/detail/replyReply/index.dart'; import 'package:pilipala/plugin/pl_player/index.dart'; import 'package:pilipala/utils/storage.dart'; import 'package:pilipala/utils/utils.dart'; +import 'package:screen_brightness/screen_brightness.dart'; class VideoDetailController extends GetxController with GetSingleTickerProviderStateMixin { @@ -68,6 +69,8 @@ class VideoDetailController extends GetxController late String videoUrl; late String audioUrl; late Duration defaultST; + // 亮度 + double? brightness; // 默认记录历史记录 bool enableHeart = true; var userInfo; @@ -152,6 +155,12 @@ class VideoDetailController extends GetxController } Future playerInit({video, audio, seekToTime, duration}) async { + /// 设置/恢复 屏幕亮度 + if (brightness != null) { + ScreenBrightness().setScreenBrightness(brightness!); + } else { + ScreenBrightness().resetScreenBrightness(); + } await plPlayerController.setDataSource( DataSource( videoSource: video ?? videoUrl, diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 0d488115..d45bcfb9 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -45,6 +45,7 @@ class _VideoDetailPageState extends State double doubleOffset = 0; Box localCache = GStrorage.localCache; + Box setting = GStrorage.setting; late double statusBarHeight; final videoHeight = Get.size.width * 9 / 16; late Future _futureBuilderFuture; @@ -104,6 +105,10 @@ class _VideoDetailPageState extends State @override // 离开当前页面时 void didPushNext() async { + /// 开启 + if (setting.get(SettingBoxKey.enableAutoBrightness, defaultValue: false)) { + videoDetailController.brightness = plPlayerController!.brightness.value; + } videoDetailController.defaultST = plPlayerController!.position.value; videoIntroController.isPaused = true; plPlayerController!.pause(); diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 33bd7015..861c7898 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -619,7 +619,7 @@ class PlPlayerController { try { brightness.value = brightnes; ScreenBrightness().setScreenBrightness(brightnes); - setVideoBrightness(); + // setVideoBrightness(); } catch (e) { throw 'Failed to set brightness'; } @@ -662,27 +662,24 @@ class PlPlayerController { } /// 缓存fit - Future setVideoFit() async { - videoStorage.put(VideoBoxKey.videoBrightness, _videoFit.value.name); - } + // Future setVideoFit() async { + // videoStorage.put(VideoBoxKey.videoBrightness, _videoFit.value.name); + // } /// 读取fit - Future getVideoFit() async { - String fitValue = - videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain'); - _videoFit.value = videoFitType - .firstWhere((element) => element['attr'] == fitValue)['attr']; - } - - /// 缓存亮度 - Future setVideoBrightness() async {} + // Future getVideoFit() async { + // String fitValue = + // videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain'); + // _videoFit.value = videoFitType + // .firstWhere((element) => element['attr'] == fitValue)['attr']; + // } /// 读取亮度 - Future getVideoBrightness() async { - double brightnessValue = - videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 0.5); - setBrightness(brightnessValue); - } + // Future getVideoBrightness() async { + // double brightnessValue = + // videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 0.5); + // setBrightness(brightnessValue); + // } set controls(bool visible) { _showControls.value = visible; @@ -791,6 +788,8 @@ class PlPlayerController { await _videoPlayerController?.dispose(); _videoPlayerController = null; _instance = null; + // 关闭所有视频页面恢复亮度 + resetBrightness(); } catch (err) { print(err); } diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 7ba5de18..48c016c9 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -156,6 +156,7 @@ class _PLVideoPlayerState extends State }); } }); + widget.controller.brightness.value = value; } Future triggerFullScreen() async { diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index a8d0507f..a117760e 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -96,6 +96,7 @@ class SettingBoxKey { static const String defaultPicQa = 'defaultPicQa'; static const String enableHA = 'enableHA'; static const String enableOnlineTotal = 'enableOnlineTotal'; + static const String enableAutoBrightness = 'enableAutoBrightness'; /// 隐私 static const String blackMidsList = 'blackMidsList';