From 0c067f7ca69713ca5736d1d3fe4f73552fc3846b Mon Sep 17 00:00:00 2001 From: guozhigq Date: Thu, 17 Aug 2023 14:32:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=86=E9=A2=91=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugin/pl_player/controller.dart | 37 ++++++++++++------- .../pl_player/widgets/bottom_control.dart | 18 ++++----- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index b291db1a..797a2ffe 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:media_kit/media_kit.dart'; @@ -68,7 +69,7 @@ class PlPlayerController { final Rx _direction = 'horizontal'.obs; Rx videoFitChanged = false.obs; - final Rx _videoFit = Rx(BoxFit.fill); + final Rx _videoFit = Rx(BoxFit.contain); /// // ignore: prefer_final_fields @@ -93,13 +94,13 @@ class PlPlayerController { // final Durations durations; - List fits = [ - BoxFit.contain, - BoxFit.cover, - BoxFit.fill, - BoxFit.fitHeight, - BoxFit.fitWidth, - BoxFit.scaleDown + List> videoFitType = [ + {'attr': BoxFit.contain, 'desc': '包含'}, + {'attr': BoxFit.cover, 'desc': '覆盖'}, + {'attr': BoxFit.fill, 'desc': '填充'}, + {'attr': BoxFit.fitHeight, 'desc': '高度适应'}, + {'attr': BoxFit.fitWidth, 'desc': '宽度适应'}, + {'attr': BoxFit.scaleDown, 'desc': '缩小适应'}, ]; PreferredSizeWidget? headerControl; @@ -631,10 +632,17 @@ class PlPlayerController { void toggleVideoFit() { videoFitChangedTimer?.cancel(); videoFitChanged.value = true; - if (fits.indexOf(_videoFit.value) < fits.length - 1) { - _videoFit.value = fits[fits.indexOf(_videoFit.value) + 1]; + // 范围内 + List attrs = videoFitType.map((e) => e['attr']).toList(); + if (attrs.indexOf(_videoFit.value) < attrs.length - 1) { + int index = attrs.indexOf(_videoFit.value); + _videoFit.value = attrs[index + 1]; + print(videoFitType[index + 1]['desc']); + SmartDialog.showToast(videoFitType[index + 1]['desc']); } else { - _videoFit.value = fits[0]; + // 默认 contain + _videoFit.value = videoFitType.first['attr']; + SmartDialog.showToast(videoFitType.first['desc']); } videoFitChangedTimer = Timer(const Duration(seconds: 1), () { videoFitChangedTimer = null; @@ -655,9 +663,10 @@ class PlPlayerController { /// 读取fit Future getVideoFit() async { - String fitValue = videoStorage.get(VideoBoxKey.videoBrightness, - defaultValue: 'fitHeight'); - _videoFit.value = fits.firstWhere((element) => element.name == fitValue); + String fitValue = + videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain'); + _videoFit.value = videoFitType + .firstWhere((element) => element['attr'] == fitValue)['attr']; } /// 缓存亮度 diff --git a/lib/plugin/pl_player/widgets/bottom_control.dart b/lib/plugin/pl_player/widgets/bottom_control.dart index e73236fc..1cd4c20d 100644 --- a/lib/plugin/pl_player/widgets/bottom_control.dart +++ b/lib/plugin/pl_player/widgets/bottom_control.dart @@ -130,15 +130,15 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { // ), // ), // ), - // ComBtn( - // icon: const Icon( - // Icons.fit_screen_sharp, - // size: 18, - // color: Colors.white, - // ), - // fuc: () => _.toggleVideoFit(), - // ), - // const SizedBox(width: 4), + ComBtn( + icon: const Icon( + Icons.settings_overscan_outlined, + size: 18, + color: Colors.white, + ), + fuc: () => _.toggleVideoFit(), + ), + const SizedBox(width: 4), // 全屏 Obx( () => ComBtn(