Skip to content

Commit

Permalink
add default play speed settings (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
Predidit committed Sep 15, 2024
1 parent 3cc601c commit 7272410
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 64 deletions.
3 changes: 2 additions & 1 deletion lib/pages/player/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ abstract class _PlayerController with Store {
videoPageController.title, videoPageController.currentEspisode);
mediaPlayer = await createVideoController();
bool aotoPlay = setting.get(SettingBoxKey.autoPlay, defaultValue: true);
playerSpeed = 1.0;
playerSpeed = setting.get(SettingBoxKey.defaultPlaySpeed, defaultValue: 1.0);
if (offset != 0) {
await mediaPlayer.seekTo(Duration(seconds: offset));
}
if (aotoPlay) {
await mediaPlayer.play();
}
setPlaybackSpeed(playerSpeed);
KazumiLogger().log(Level.info, 'VideoURL初始化完成');
// 加载弹幕
loading = false;
Expand Down
17 changes: 2 additions & 15 deletions lib/pages/player/player_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import 'package:kazumi/request/damaku.dart';
import 'package:kazumi/modules/danmaku/danmaku_search_response.dart';
import 'package:kazumi/bean/appbar/drag_to_move_bar.dart' as dtb;
import 'package:kazumi/pages/settings/danmaku/danmaku_settings_window.dart';
import 'package:kazumi/utils/constans.dart';

class PlayerItem extends StatefulWidget {
const PlayerItem({super.key});
Expand Down Expand Up @@ -322,20 +323,6 @@ class _PlayerItemState extends State<PlayerItem>
// 选择倍速
void showSetSpeedSheet() {
final double currentSpeed = playerController.playerSpeed;
final List<double> speedsList = [
0.25,
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
2.0,
2.25,
2.5,
2.75,
3.0
];
SmartDialog.show(
useAnimation: false,
builder: (context) {
Expand All @@ -347,7 +334,7 @@ class _PlayerItemState extends State<PlayerItem>
spacing: 8,
runSpacing: 2,
children: [
for (final double i in speedsList) ...<Widget>[
for (final double i in playSpeedList) ...<Widget>[
if (i == currentSpeed) ...<Widget>[
FilledButton(
onPressed: () async {
Expand Down
44 changes: 1 addition & 43 deletions lib/pages/settings/danmaku/danmaku_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:hive/hive.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:kazumi/pages/popular/popular_controller.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:kazumi/utils/constans.dart';

class DanmakuSettingsPage extends StatefulWidget {
const DanmakuSettingsPage({super.key});
Expand Down Expand Up @@ -144,31 +145,6 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
),
ListTile(
onTap: () async {
final List<double> danFontList = [
10.0,
11.0,
12.0,
13.0,
14.0,
15.0,
16.0,
17.0,
18.0,
19.0,
20.0,
21.0,
22.0,
23.0,
24.0,
25.0,
26.0,
27.0,
28.0,
29.0,
30.0,
31.0,
32.0,
];
SmartDialog.show(
useAnimation: false,
builder: (context) {
Expand Down Expand Up @@ -235,18 +211,6 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
),
ListTile(
onTap: () async {
final List<double> danOpacityList = [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8,
0.9,
1.0,
];
SmartDialog.show(
useAnimation: false,
builder: (context) {
Expand Down Expand Up @@ -311,12 +275,6 @@ class _DanmakuSettingsPageState extends State<DanmakuSettingsPage> {
),
ListTile(
onTap: () async {
final List<double> danAreaList = [
0.25,
0.5,
0.75,
1.0,
];
SmartDialog.show(
useAnimation: false,
builder: (context) {
Expand Down
87 changes: 82 additions & 5 deletions lib/pages/settings/player_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:provider/provider.dart';
import 'package:kazumi/pages/menu/menu.dart';
import 'package:kazumi/pages/menu/side_menu.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:hive/hive.dart';
import 'package:kazumi/utils/constans.dart';

class PlayerSettingsPage extends StatefulWidget {
const PlayerSettingsPage({super.key});
Expand All @@ -15,11 +18,15 @@ class PlayerSettingsPage extends StatefulWidget {
}

class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
Box setting = GStorage.setting;
dynamic navigationBarState;
late double defaultPlaySpeed;

@override
void initState() {
super.initState();
defaultPlaySpeed =
setting.get(SettingBoxKey.defaultPlaySpeed, defaultValue: 1.0);
if (Utils.isCompact()) {
navigationBarState =
Provider.of<NavigationBarState>(context, listen: false);
Expand All @@ -34,6 +41,13 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
// Navigator.of(context).pop();
}

void updateDefaultPlaySpeed(double speed) {
setting.put(SettingBoxKey.defaultPlaySpeed, speed);
setState(() {
defaultPlaySpeed = speed;
});
}

@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Expand All @@ -44,19 +58,19 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
onPopInvokedWithResult: (bool didPop, Object? result) {
onBackPressed(context);
},
child: const Scaffold(
appBar: SysAppBar(title: Text('播放设置')),
child: Scaffold(
appBar: const SysAppBar(title: Text('播放设置')),
body: Column(
children: [
InkWell(
const InkWell(
child: SetSwitchItem(
title: '硬件解码',
setKey: SettingBoxKey.hAenable,
needReboot: true,
defaultVal: true,
),
),
InkWell(
const InkWell(
child: SetSwitchItem(
title: '低内存模式',
subTitle: '禁用高级缓存以减少内存占用',
Expand All @@ -65,14 +79,77 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
defaultVal: false,
),
),
InkWell(
const InkWell(
child: SetSwitchItem(
title: '自动跳转',
subTitle: '跳转到上次播放位置',
setKey: SettingBoxKey.playResume,
defaultVal: true,
),
),
ListTile(
onTap: () async {
SmartDialog.show(
useAnimation: false,
builder: (context) {
return AlertDialog(
title: const Text('默认倍速'),
content: StatefulBuilder(builder:
(BuildContext context, StateSetter setState) {
return Wrap(
spacing: 8,
runSpacing: 2,
children: [
for (final double i in playSpeedList) ...<Widget>[
if (i == defaultPlaySpeed) ...<Widget>[
FilledButton(
onPressed: () async {
updateDefaultPlaySpeed(i);
SmartDialog.dismiss();
},
child: Text(i.toString()),
),
] else ...[
FilledButton.tonal(
onPressed: () async {
updateDefaultPlaySpeed(i);
SmartDialog.dismiss();
},
child: Text(i.toString()),
),
]
]
],
);
}),
actions: <Widget>[
TextButton(
onPressed: () => SmartDialog.dismiss(),
child: Text(
'取消',
style: TextStyle(
color: Theme.of(context).colorScheme.outline),
),
),
TextButton(
onPressed: () async {
updateDefaultPlaySpeed(1.0);
SmartDialog.dismiss();
},
child: const Text('默认设置'),
),
],
);
});
},
dense: false,
title: const Text('默认倍速'),
subtitle: Text('$defaultPlaySpeed',
style: Theme.of(context)
.textTheme
.labelMedium!
.copyWith(color: Theme.of(context).colorScheme.outline)),
),
],
),
),
Expand Down
66 changes: 66 additions & 0 deletions lib/utils/constans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class StyleString {
static const double aspectRatio = 16 / 10;
}

// 随机UA列表
const List<String> userAgentsList = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
Expand All @@ -28,3 +29,68 @@ Map<String, String> bangumiHTTPHeader = {
'Predidit/Kazumi/${Api.version} (Android) (https://github.com/Predidit/Kazumi)',
'referer': '',
};

// 可选播放倍速
const List<double> playSpeedList = [
0.25,
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
2.0,
2.25,
2.5,
2.75,
3.0
];

// 可选弹幕透明度
const List<double> danOpacityList = [
0.1,
0.2,
0.3,
0.4,
0.5,
0.6,
0.7,
0.8,
0.9,
1.0,
];

// 可选弹幕字体大小
final List<double> danFontList = [
10.0,
11.0,
12.0,
13.0,
14.0,
15.0,
16.0,
17.0,
18.0,
19.0,
20.0,
21.0,
22.0,
23.0,
24.0,
25.0,
26.0,
27.0,
28.0,
29.0,
30.0,
31.0,
32.0,
];

// 可选弹幕区域
const List<double> danAreaList = [
0.25,
0.5,
0.75,
1.0,
];
1 change: 1 addition & 0 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class SettingBoxKey {
searchEnhanceEnable = 'searchEnhanceEnable',
autoUpdate = 'autoUpdate',
alwaysOntop = 'alwaysOntop',
defaultPlaySpeed = 'defaultPlaySpeed',
danmakuEnhance = 'danmakuEnhance',
danmakuBorder = 'danmakuBorder',
danmakuOpacity = 'danmakuOpacity',
Expand Down

0 comments on commit 7272410

Please sign in to comment.