From aa95d9020d5ca9ae1ba9b9710565ee79d1a4528d Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sat, 21 Oct 2023 22:15:18 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E7=94=BB=E9=9D=A2=E6=AF=94=E4=BE=8B?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin/pl_player/controller.dart | 33 +++++++++---------- .../pl_player/widgets/bottom_control.dart | 21 ++++++++---- lib/utils/storage.dart | 2 ++ 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index c44dd99b..5bc3fc32 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -73,6 +73,7 @@ class PlPlayerController { Rx videoFitChanged = false.obs; final Rx _videoFit = Rx(BoxFit.contain); + final Rx _videoFitDesc = Rx('包含'); /// // ignore: prefer_final_fields @@ -183,6 +184,7 @@ class PlPlayerController { /// 视频比例 Rx get videoFit => _videoFit; + Rx get videoFitDEsc => _videoFitDesc; /// 是否长按倍速 Rx get doubleSpeedStatus => _doubleSpeedStatus; @@ -443,7 +445,7 @@ class PlPlayerController { } else { await setPlaybackSpeed(1.0); } - + getVideoFit(); // if (_looping) { // await setLooping(_looping); // } @@ -731,37 +733,34 @@ class PlPlayerController { if (attrs.indexOf(_videoFit.value) < attrs.length - 1) { int index = attrs.indexOf(_videoFit.value); _videoFit.value = attrs[index + 1]; - print(videoFitType[index + 1]['desc']); + _videoFitDesc.value = videoFitType[index + 1]['desc']; SmartDialog.showToast(videoFitType[index + 1]['desc']); } else { // 默认 contain _videoFit.value = videoFitType.first['attr']; + _videoFitDesc.value = videoFitType.first['desc']; SmartDialog.showToast(videoFitType.first['desc']); } videoFitChangedTimer = Timer(const Duration(seconds: 1), () { videoFitChangedTimer = null; videoFitChanged.value = false; }); - print(_videoFit.value); - } - - /// Change Video Fit accordingly - void onVideoFitChange(BoxFit fit) { - _videoFit.value = fit; + setVideoFit(); } /// 缓存fit - // Future setVideoFit() async { - // videoStorage.put(VideoBoxKey.videoBrightness, _videoFit.value.name); - // } + Future setVideoFit() async { + List attrs = videoFitType.map((e) => e['attr']).toList(); + int index = attrs.indexOf(_videoFit.value); + videoStorage.put(VideoBoxKey.cacheVideoFit, index); + } /// 读取fit - // Future getVideoFit() async { - // String fitValue = - // videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain'); - // _videoFit.value = videoFitType - // .firstWhere((element) => element['attr'] == fitValue)['attr']; - // } + Future getVideoFit() async { + int fitValue = videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0); + _videoFit.value = videoFitType[fitValue]['attr']; + _videoFitDesc.value = videoFitType[fitValue]['desc']; + } /// 读取亮度 // Future getVideoBrightness() async { diff --git a/lib/plugin/pl_player/widgets/bottom_control.dart b/lib/plugin/pl_player/widgets/bottom_control.dart index fb0f42b6..dbd93b08 100644 --- a/lib/plugin/pl_player/widgets/bottom_control.dart +++ b/lib/plugin/pl_player/widgets/bottom_control.dart @@ -115,13 +115,20 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { // ), // ), // ), - ComBtn( - icon: const Icon( - Icons.settings_overscan_outlined, - size: 18, - color: Colors.white, + SizedBox( + height: 30, + child: TextButton( + onPressed: () => _.toggleVideoFit(), + style: ButtonStyle( + padding: MaterialStateProperty.all(EdgeInsets.zero), + ), + child: Obx( + () => Text( + _.videoFitDEsc.value, + style: const TextStyle(color: Colors.white, fontSize: 13), + ), + ), ), - fuc: () => _.toggleVideoFit(), ), const SizedBox(width: 4), // 全屏 @@ -139,7 +146,7 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { ), ], ), - const SizedBox(height: 10), + const SizedBox(height: 8), ], ), ); diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 4689d7f2..ea30253b 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -170,4 +170,6 @@ class VideoBoxKey { static const String longPressSpeedDefault = 'longPressSpeedDefault'; // 自定义倍速集合 static const String customSpeedsList = 'customSpeedsList'; + // 画面填充比例 + static const String cacheVideoFit = 'cacheVideoFit'; }