Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] 允许自定义倍速 #759

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/pages/player/player_item_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PlayerItemPanel extends StatefulWidget {
class _PlayerItemPanelState extends State<PlayerItemPanel> {
Box setting = GStorage.setting;
late bool haEnable;
late List<double> PlaySpeedList;
late Animation<Offset> topOffsetAnimation;
late Animation<Offset> bottomOffsetAnimation;
late Animation<Offset> leftOffsetAnimation;
Expand Down Expand Up @@ -172,7 +173,8 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
spacing: 8,
runSpacing: Utils.isDesktop() ? 8 : 0,
children: [
for (final double i in defaultPlaySpeedList) ...<Widget>[

for (final double i in PlaySpeedList) ...<Widget>[
if (i == currentSpeed)
FilledButton(
onPressed: () async {
Expand Down Expand Up @@ -283,6 +285,8 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
curve: Curves.easeInOut,
));
haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);
PlaySpeedList =
setting.get(SettingBoxKey.PlaySpeedList, defaultValue: defaultPlaySpeedList_L);
}

Widget forwardIcon() {
Expand Down Expand Up @@ -1023,7 +1027,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
},
menuChildren: [
for (final double i
in defaultPlaySpeedList) ...<MenuItemButton>[
in PlaySpeedList) ...<MenuItemButton>[
MenuItemButton(
onPressed: () async {
await widget.setPlaybackSpeed(i);
Expand Down
4 changes: 3 additions & 1 deletion lib/pages/player/smallest_player_item_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class SmallestPlayerItemPanel extends StatefulWidget {
class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
Box setting = GStorage.setting;
late bool haEnable;
late List<double> PlaySpeedList;
late Animation<Offset> topOffsetAnimation;
late Animation<Offset> bottomOffsetAnimation;
late Animation<Offset> leftOffsetAnimation;
Expand Down Expand Up @@ -136,6 +137,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
curve: Curves.easeInOut,
));
haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);
PlaySpeedList = setting.get(SettingBoxKey.PlaySpeedList, defaultValue: defaultPlaySpeedList_L);
}

Widget forwardIcon() {
Expand Down Expand Up @@ -452,7 +454,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
SubmenuButton(
menuChildren: [
for (final double i
in defaultPlaySpeedList) ...<MenuItemButton>[
in PlaySpeedList) ...<MenuItemButton>[
MenuItemButton(
onPressed: () async {
await widget.setPlaybackSpeed(i);
Expand Down
67 changes: 66 additions & 1 deletion lib/pages/settings/player_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
late bool showPlayerError;
late bool privateMode;
late bool playerDebugMode;
late List<double> PlaySpeedList;

@override
void initState() {
Expand All @@ -39,6 +40,9 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
setting.get(SettingBoxKey.showPlayerError, defaultValue: true);
playerDebugMode =
setting.get(SettingBoxKey.playerDebugMode, defaultValue: false);
PlaySpeedList =
setting.get(SettingBoxKey.PlaySpeedList, defaultValue: defaultPlaySpeedList_L);

}

void onBackPressed(BuildContext context) {
Expand Down Expand Up @@ -161,7 +165,7 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
content: StatefulBuilder(builder:
(BuildContext context, StateSetter setState) {
final List<double> playSpeedList;
playSpeedList = defaultPlaySpeedList;
playSpeedList = PlaySpeedList;
return Wrap(
spacing: 8,
runSpacing: Utils.isDesktop() ? 8 : 0,
Expand Down Expand Up @@ -207,6 +211,67 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
},
child: const Text('默认设置'),
),

TextButton(
onPressed: () async {
double newSpeed = defaultPlaySpeed;

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('添加倍速'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('输入你想要的视频倍速,例如:1.0'),
const SizedBox(height: 12),
TextField(
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: InputDecoration(
labelText: '自定义倍速',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onChanged: (value) {
final parsed = double.tryParse(value);
if (parsed != null && parsed > 0 && parsed < 5) {
newSpeed = parsed;
}
},
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消'),
),
TextButton(
onPressed: () {
PlaySpeedList.add(newSpeed);
updateDefaultPlaySpeed(newSpeed);

setting.put(
SettingBoxKey.PlaySpeedList,
PlaySpeedList
);

setState(() {});

Navigator.pop(context);
},
child: const Text('确认添加'),
)
],
);
},
);
KazumiDialog.dismiss();
},
child: const Text('添加倍速'),
),
],
);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const List<String> mpvAnime4KShadersLite = [
];

// 可选播放倍速
const List<double> defaultPlaySpeedList = [
List<double> defaultPlaySpeedList_L = [
0.25,
0.5,
0.75,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class SettingBoxKey {
autoUpdate = 'autoUpdate',
alwaysOntop = 'alwaysOntop',
defaultPlaySpeed = 'defaultPlaySpeed',
PlaySpeedList = 'PlaySpeedList',
danmakuEnhance = 'danmakuEnhance',
danmakuBorder = 'danmakuBorder',
danmakuOpacity = 'danmakuOpacity',
Expand Down
Loading