From 08aedbf0b0df0de39e411997b67d2fad2231dca1 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 4 Apr 2025 10:35:52 +0800 Subject: [PATCH] feat: custom for/backward duration Closes #366 Closes #601 Signed-off-by: bggRGjQaUbCoE --- lib/pages/setting/widgets/model.dart | 21 +++++++++++++++---- lib/plugin/pl_player/controller.dart | 1 + lib/plugin/pl_player/view.dart | 4 ++++ .../pl_player/widgets/backward_seek.dart | 16 ++++++++------ .../pl_player/widgets/forward_seek.dart | 16 ++++++++------ lib/utils/storage.dart | 4 ++++ 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/lib/pages/setting/widgets/model.dart b/lib/pages/setting/widgets/model.dart index da22b9953..58e666dd9 100644 --- a/lib/pages/setting/widgets/model.dart +++ b/lib/pages/setting/widgets/model.dart @@ -759,6 +759,15 @@ List get playSettings => [ setKey: SettingBoxKey.enableSlideFS, defaultVal: true, ), + _getVideoFilterSelectModel( + context: Get.context!, + title: '快进/快退时长', + suffix: 's', + key: SettingBoxKey.fastForBackwardDuration, + values: [5, 10, 15], + defaultValue: 10, + isFilter: false, + ), SettingsModel( settingsType: SettingsType.normal, title: '自动启用字幕', @@ -2479,19 +2488,23 @@ SettingsModel _getVideoFilterSelectModel({ String? suffix, required String key, required List values, + int defaultValue = 0, + bool isFilter = true, }) { - int value = GStorage.setting.get(key, defaultValue: 0); + int value = GStorage.setting.get(key, defaultValue: defaultValue); return SettingsModel( settingsType: SettingsType.normal, - title: '$title过滤', + title: '$title${isFilter ? '过滤' : ''}', leading: const Icon(Icons.timelapse_outlined), - getSubtitle: () => '过滤掉$title小于「$value${suffix ?? ""}」的视频', + getSubtitle: () => isFilter + ? '过滤掉$title小于「$value${suffix ?? ""}」的视频' + : '当前$title:「$value${suffix ?? ""}」', onTap: (setState) async { var result = await showDialog( context: context, builder: (context) { return SelectDialog( - title: '选择$title(0即不过滤)', + title: '选择$title${isFilter ? '(0即不过滤)' : ''}', value: value, values: (values ..addIf(!values.contains(value), value) diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 450be3273..c9844bbff 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -257,6 +257,7 @@ class PlPlayerController { late final enableSlideVolumeBrightness = GStorage.enableSlideVolumeBrightness; late final enableSlideFS = GStorage.enableSlideFS; late final enableDragSubtitle = GStorage.enableDragSubtitle; + late final fastForBackwardDuration = GStorage.fastForBackwardDuration; /// 弹幕权重 int danmakuWeight = 0; diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index a15c68f4b..7e9192f4f 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -1704,6 +1704,8 @@ class _PLVideoPlayerState extends State child: child, ), child: BackwardSeekIndicator( + duration: + plPlayerController.fastForBackwardDuration, onSubmitted: (Duration value) { _mountSeekBackwardButton.value = false; final Player player = widget @@ -1733,6 +1735,8 @@ class _PLVideoPlayerState extends State child: child, ), child: ForwardSeekIndicator( + duration: + plPlayerController.fastForBackwardDuration, onSubmitted: (Duration value) { _mountSeekForwardButton.value = false; final Player player = widget diff --git a/lib/plugin/pl_player/widgets/backward_seek.dart b/lib/plugin/pl_player/widgets/backward_seek.dart index 572379922..0c288fe7f 100644 --- a/lib/plugin/pl_player/widgets/backward_seek.dart +++ b/lib/plugin/pl_player/widgets/backward_seek.dart @@ -4,11 +4,14 @@ import 'package:flutter/material.dart'; class BackwardSeekIndicator extends StatefulWidget { // final void Function(Duration) onChanged; - final void Function(Duration) onSubmitted; + final ValueChanged onSubmitted; + final int duration; + const BackwardSeekIndicator({ super.key, // required this.onChanged, required this.onSubmitted, + required this.duration, }); @override @@ -16,15 +19,16 @@ class BackwardSeekIndicator extends StatefulWidget { } class BackwardSeekIndicatorState extends State { - Duration value = const Duration(seconds: 10); + late Duration duration; Timer? timer; @override void initState() { super.initState(); + duration = Duration(seconds: widget.duration); timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); + widget.onSubmitted.call(duration); }); } @@ -37,12 +41,12 @@ class BackwardSeekIndicatorState extends State { void increment() { timer?.cancel(); timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); + widget.onSubmitted.call(duration); }); // widget.onChanged.call(value); // 重复点击 快退秒数累加10 setState(() { - value += const Duration(seconds: 10); + duration += Duration(seconds: widget.duration); }); } @@ -75,7 +79,7 @@ class BackwardSeekIndicatorState extends State { ), const SizedBox(height: 8.0), Text( - '快退${value.inSeconds}秒', + '快退${duration.inSeconds}秒', style: const TextStyle( fontSize: 12.0, color: Colors.white, diff --git a/lib/plugin/pl_player/widgets/forward_seek.dart b/lib/plugin/pl_player/widgets/forward_seek.dart index 7fdb0ebc7..156f4e340 100644 --- a/lib/plugin/pl_player/widgets/forward_seek.dart +++ b/lib/plugin/pl_player/widgets/forward_seek.dart @@ -4,11 +4,14 @@ import 'package:flutter/material.dart'; class ForwardSeekIndicator extends StatefulWidget { // final void Function(Duration) onChanged; - final void Function(Duration) onSubmitted; + final ValueChanged onSubmitted; + final int duration; + const ForwardSeekIndicator({ super.key, // required this.onChanged, required this.onSubmitted, + required this.duration, }); @override @@ -16,15 +19,16 @@ class ForwardSeekIndicator extends StatefulWidget { } class ForwardSeekIndicatorState extends State { - Duration value = const Duration(seconds: 10); + late Duration duration; Timer? timer; @override void initState() { super.initState(); + duration = Duration(seconds: widget.duration); timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); + widget.onSubmitted.call(duration); }); } @@ -37,12 +41,12 @@ class ForwardSeekIndicatorState extends State { void increment() { timer?.cancel(); timer = Timer(const Duration(milliseconds: 400), () { - widget.onSubmitted.call(value); + widget.onSubmitted.call(duration); }); // widget.onChanged.call(value); // 重复点击 快进秒数累加10 setState(() { - value += const Duration(seconds: 10); + duration += Duration(seconds: widget.duration); }); } @@ -74,7 +78,7 @@ class ForwardSeekIndicatorState extends State { ), const SizedBox(height: 8.0), Text( - '快进${value.inSeconds}秒', + '快进${duration.inSeconds}秒', style: const TextStyle( fontSize: 12.0, color: Colors.white, diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 8f58c1305..75b2d5e4b 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -439,6 +439,9 @@ class GStorage { static bool get enableDragSubtitle => GStorage.setting .get(SettingBoxKey.enableDragSubtitle, defaultValue: false); + static int get fastForBackwardDuration => GStorage.setting + .get(SettingBoxKey.fastForBackwardDuration, defaultValue: 10); + static List get dynamicDetailRatio => List.from(setting .get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0])); @@ -720,6 +723,7 @@ class SettingBoxKey { liveQualityCellular = 'liveQualityCellular', appFontWeight = 'appFontWeight', enableDragSubtitle = 'enableDragSubtitle', + fastForBackwardDuration = 'fastForBackwardDuration', // Sponsor Block enableSponsorBlock = 'enableSponsorBlock',