From 3ece2bb173ad31caa0638cc400d49190718db254 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 10 Mar 2024 17:57:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E5=80=8D=E9=80=9F?= =?UTF-8?q?=E5=8F=AF=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../live_room/widgets/bottom_control.dart | 1 - lib/pages/setting/pages/play_speed_set.dart | 101 +++++++++--------- .../video/detail/widgets/header_control.dart | 1 - lib/plugin/pl_player/controller.dart | 26 ++--- lib/plugin/pl_player/models/play_speed.dart | 46 ++------ lib/utils/storage.dart | 2 + 6 files changed, 77 insertions(+), 100 deletions(-) diff --git a/lib/pages/live_room/widgets/bottom_control.dart b/lib/pages/live_room/widgets/bottom_control.dart index a00f3d92..7ec8864f 100644 --- a/lib/pages/live_room/widgets/bottom_control.dart +++ b/lib/pages/live_room/widgets/bottom_control.dart @@ -29,7 +29,6 @@ class BottomControl extends StatefulWidget implements PreferredSizeWidget { class _BottomControlState extends State { late PlayUrlModel videoInfo; - List playSpeed = PlaySpeed.values; TextStyle subTitleStyle = const TextStyle(fontSize: 12); TextStyle titleStyle = const TextStyle(fontSize: 14); Size get preferredSize => const Size(double.infinity, kToolbarHeight); diff --git a/lib/pages/setting/pages/play_speed_set.dart b/lib/pages/setting/pages/play_speed_set.dart index ceff07ed..eb81f586 100644 --- a/lib/pages/setting/pages/play_speed_set.dart +++ b/lib/pages/setting/pages/play_speed_set.dart @@ -17,6 +17,7 @@ class _PlaySpeedPageState extends State { Box videoStorage = GStrorage.video; Box settingStorage = GStrorage.setting; late double playSpeedDefault; + late List playSpeedSystem; late double longPressSpeedDefault; late List customSpeedsList; late bool enableAutoLongPressSpeed; @@ -53,6 +54,9 @@ class _PlaySpeedPageState extends State { @override void initState() { super.initState(); + // 系统预设倍速 + playSpeedSystem = + videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed); // 默认倍速 playSpeedDefault = videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0); @@ -64,6 +68,7 @@ class _PlaySpeedPageState extends State { videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []); enableAutoLongPressSpeed = settingStorage .get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false); + // 开启动态长按倍速时不展示 if (enableAutoLongPressSpeed) { Map newItem = sheetMenu[1]; newItem['show'] = false; @@ -123,7 +128,7 @@ class _PlaySpeedPageState extends State { } // 设定倍速弹窗 - void showBottomSheet(type, i) { + void showBottomSheet(String type, int i) { showModalBottomSheet( context: context, isScrollControlled: true, @@ -159,18 +164,11 @@ class _PlaySpeedPageState extends State { } // - void menuAction(type, index, id) async { + void menuAction(type, int index, id) async { double chooseSpeed = 1.0; - if (type == 'system' && id == -1) { - SmartDialog.showToast('系统预设倍速不支持删除'); - return; - } // 获取当前选中的倍速值 - if (type == 'system') { - chooseSpeed = PlaySpeed.values[index].value; - } else { - chooseSpeed = customSpeedsList[index]; - } + chooseSpeed = + type == 'system' ? playSpeedSystem[index] : customSpeedsList[index]; // 设置 if (id == 1) { // 设置默认倍速 @@ -182,17 +180,22 @@ class _PlaySpeedPageState extends State { videoStorage.put( VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault); } else if (id == -1) { - if (customSpeedsList[index] == playSpeedDefault) { - playSpeedDefault = 1.0; - videoStorage.put(VideoBoxKey.playSpeedDefault, playSpeedDefault); + late List speedsList = + type == 'system' ? playSpeedSystem : customSpeedsList; + if (speedsList[index] == playSpeedDefault) { + SmartDialog.showToast('默认倍速不可删除'); } - if (customSpeedsList[index] == longPressSpeedDefault) { + if (speedsList[index] == longPressSpeedDefault) { longPressSpeedDefault = 2.0; videoStorage.put( VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault); } - customSpeedsList.removeAt(index); - await videoStorage.put(VideoBoxKey.customSpeedsList, customSpeedsList); + speedsList.removeAt(index); + await videoStorage.put( + type == 'system' + ? VideoBoxKey.playSpeedSystem + : VideoBoxKey.customSpeedsList, + speedsList); } setState(() {}); SmartDialog.showToast('操作成功'); @@ -249,38 +252,40 @@ class _PlaySpeedPageState extends State { subtitle: Text(longPressSpeedDefault.toString()), ) : const SizedBox(), - Padding( - padding: const EdgeInsets.only( - left: 14, - right: 14, - bottom: 10, - top: 20, + if (playSpeedSystem.isNotEmpty) ...[ + Padding( + padding: const EdgeInsets.only( + left: 14, + right: 14, + bottom: 10, + top: 20, + ), + child: Text( + '系统预设倍速', + style: Theme.of(context).textTheme.titleMedium, + ), ), - child: Text( - '系统预设倍速', - style: Theme.of(context).textTheme.titleMedium, - ), - ), - Padding( - padding: const EdgeInsets.only( - left: 18, - right: 18, - bottom: 30, - ), - child: Wrap( - alignment: WrapAlignment.start, - spacing: 8, - runSpacing: 2, - children: [ - for (var i in PlaySpeed.values) ...[ - FilledButton.tonal( - onPressed: () => showBottomSheet('system', i.index), - child: Text(i.description), - ), - ] - ], - ), - ), + Padding( + padding: const EdgeInsets.only( + left: 18, + right: 18, + bottom: 30, + ), + child: Wrap( + alignment: WrapAlignment.start, + spacing: 8, + runSpacing: 2, + children: [ + for (int i = 0; i < playSpeedSystem.length; i++) ...[ + FilledButton.tonal( + onPressed: () => showBottomSheet('system', i), + child: Text(playSpeedSystem[i].toString()), + ), + ] + ], + ), + ) + ], Padding( padding: const EdgeInsets.only( left: 14, diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index e72e6a69..e07e618e 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -47,7 +47,6 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget { class _HeaderControlState extends State { late PlayUrlModel videoInfo; - List playSpeed = PlaySpeed.values; static const TextStyle subTitleStyle = TextStyle(fontSize: 12); static const TextStyle titleStyle = TextStyle(fontSize: 14); Size get preferredSize => const Size(double.infinity, kToolbarHeight); diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index b4b37cea..aaded67d 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -292,11 +292,19 @@ class PlPlayerController { _longPressSpeed.value = videoStorage .get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0); } + // 自定义倍速集合 speedsList = List.from(videoStorage .get(VideoBoxKey.customSpeedsList, defaultValue: [])); - for (final PlaySpeed i in PlaySpeed.values) { - speedsList.add(i.value); - } + // 默认倍速 + speedsList = List.from(videoStorage + .get(VideoBoxKey.customSpeedsList, defaultValue: [])); + //playSpeedSystem + final List playSpeedSystem = + videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed); + + // for (final PlaySpeed i in PlaySpeed.values) { + speedsList.addAll(playSpeedSystem); + // } // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // if (status == PlayerStatus.playing) { @@ -676,18 +684,6 @@ class PlPlayerController { _playbackSpeed.value = speed; } - /// 设置倍速 - // Future togglePlaybackSpeed() async { - // List allowedSpeeds = - // PlaySpeed.values.map((e) => e.value).toList(); - // int index = allowedSpeeds.indexOf(_playbackSpeed.value); - // if (index < allowedSpeeds.length - 1) { - // setPlaybackSpeed(allowedSpeeds[index + 1]); - // } else { - // setPlaybackSpeed(allowedSpeeds[0]); - // } - // } - /// 播放视频 /// TODO _duration.value丢失 Future play( diff --git a/lib/plugin/pl_player/models/play_speed.dart b/lib/plugin/pl_player/models/play_speed.dart index fd699eaf..8bb25118 100644 --- a/lib/plugin/pl_player/models/play_speed.dart +++ b/lib/plugin/pl_player/models/play_speed.dart @@ -1,39 +1,15 @@ -enum PlaySpeed { - pointTwoFive, - pointFive, - pointSevenFive, +List generatePlaySpeedList() { + List playSpeed = []; + double startSpeed = 0.25; + double endSpeed = 2.0; + double increment = 0.25; - one, - onePointTwoFive, - onePointFive, - onePointSevenFive, + for (double speed = startSpeed; speed <= endSpeed; speed += increment) { + playSpeed.add(speed); + } - two, + return playSpeed; } -extension PlaySpeedExtension on PlaySpeed { - static final List _descList = [ - '0.25', - '0.5', - '0.75', - '正常', - '1.25', - '1.5', - '1.75', - '2.0', - ]; - String get description => _descList[index]; - - static final List _valueList = [ - 0.25, - 0.5, - 0.75, - 1.0, - 1.25, - 1.5, - 1.75, - 2.0, - ]; - double get value => _valueList[index]; - double get defaultValue => _valueList[3]; -} +// 导出 playSpeed 列表 +List playSpeed = generatePlaySpeedList(); diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index fea31d56..6283299b 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -181,6 +181,8 @@ class VideoBoxKey { videoSpeed = 'videoSpeed', // 播放顺序 playRepeat = 'playRepeat', + // 系统预设倍速 + playSpeedSystem = 'playSpeedSystem', // 默认倍速 playSpeedDefault = 'playSpeedDefault', // 默认长按倍速