Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

feat: persistent aspect ratio settings (#1128)

遥遥紫荆fb2c51a5f758
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dart
index d29a66d6..881844fb 100644
--- a/lib/pages/player/player_controller.dart
+++ b/lib/pages/player/player_controller.dart
@@ -192,6 +192,8 @@ abstract class _PlayerController with Store {
mediaPlayer = await createVideoController(offset: offset);
playerSpeed =
setting.get(SettingBoxKey.defaultPlaySpeed, defaultValue: 1.0);
+ aspectRatioType =
+ setting.get(SettingBoxKey.defaultAspectRatioType, defaultValue: 1);
if (Utils.isDesktop()) {
volume = volume != -1 ? volume : 100;
await setVolume(volume);
@@ -352,6 +354,7 @@ abstract class _PlayerController with Store {
}
}
+
Future<void> setVolume(double value) async {
value = value.clamp(0.0, 100.0);
volume = value;
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index 9453737b..19da8911 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -1162,32 +1162,23 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
tooltip: '视频比例',
);
},
- menuChildren: List<MenuItemButton>.generate(
- 3,
- (int index) => MenuItemButton(
- onPressed: () => playerController
- .aspectRatioType = index + 1,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(
- 0, 10, 10, 10),
- child: Text(
- index + 1 == 1
- ? '自动'
- : index + 1 == 2
- ? '裁切填充'
- : '拉伸填充',
- style: TextStyle(
- color: index + 1 ==
- playerController
- .aspectRatioType
- ? Theme.of(context)
- .colorScheme
- .primary
- : null),
+ menuChildren: [
+ for (final entry in aspectRatioTypeMap.entries)
+ MenuItemButton(
+ onPressed: () => playerController.aspectRatioType = entry.key,
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(0, 10, 10, 10),
+ child: Text(
+ entry.value,
+ style: TextStyle(
+ color: entry.key == playerController.aspectRatioType
+ ? Theme.of(context).colorScheme.primary
+ : null,
+ ),
+ ),
),
),
- ),
- ),
+ ],
),
(!videoPageController.isFullscreen &&
!Utils.isTablet() &&
diff --git a/lib/pages/settings/player_settings.dart b/lib/pages/settings/player_settings.dart
index 7e6a590d..e68bf36d 100644
--- a/lib/pages/settings/player_settings.dart
+++ b/lib/pages/settings/player_settings.dart
@@ -19,6 +19,7 @@ class PlayerSettingsPage extends StatefulWidget {
class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
Box setting = GStorage.setting;
late double defaultPlaySpeed;
+ late int defaultAspectRatioType;
late bool hAenable;
late bool androidEnableOpenSLES;
late bool lowMemoryMode;
@@ -32,6 +33,8 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
super.initState();
defaultPlaySpeed =
setting.get(SettingBoxKey.defaultPlaySpeed, defaultValue: 1.0);
+ defaultAspectRatioType =
+ setting.get(SettingBoxKey.defaultAspectRatioType, defaultValue: 1);
hAenable = setting.get(SettingBoxKey.hAenable, defaultValue: true);
androidEnableOpenSLES =
setting.get(SettingBoxKey.androidEnableOpenSLES, defaultValue: true);
@@ -56,6 +59,12 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
});
}
+ void updateDefaultAspectRatioType(int type) {
+ setting.put(SettingBoxKey.defaultAspectRatioType, type);
+ setState(() {
+ defaultAspectRatioType = type;
+ });
+ }
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {});
@@ -231,6 +240,63 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
title: const Text('默认倍速'),
value: Text('$defaultPlaySpeed'),
),
+ SettingsTile.navigation(
+ onPressed: (_) async {
+ KazumiDialog.show(builder: (context) {
+ return AlertDialog(
+ title: const Text('默认视频比例'),
+ content: StatefulBuilder(
+ builder: (BuildContext context, StateSetter setState) {
+ return Wrap(
+ spacing: 8,
+ runSpacing: Utils.isDesktop() ? 8 : 0,
+ children: [
+ for (final entry in aspectRatioTypeMap.entries) ...<Widget>[
+ if (entry.key == defaultAspectRatioType) ...<Widget>[
+ FilledButton(
+ onPressed: () async {
+ updateDefaultAspectRatioType(entry.key);
+ KazumiDialog.dismiss();
+ },
+ child: Text(entry.value),
+ ),
+ ] else ...[
+ FilledButton.tonal(
+ onPressed: () async {
+ updateDefaultAspectRatioType(entry.key);
+ KazumiDialog.dismiss();
+ },
+ child: Text(entry.value),
+ ),
+ ]
+ ]
+ ],
+ );
+ },
+ ),
+ actions: <Widget>[
+ TextButton(
+ onPressed: () => KazumiDialog.dismiss(),
+ child: Text(
+ '取消',
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ updateDefaultAspectRatioType(1); // 默认恢复自动
+ KazumiDialog.dismiss();
+ },
+ child: const Text('默认设置'),
+ ),
+ ],
+ );
+ });
+ },
+ title: const Text('默认视频比例'),
+ value: Text(aspectRatioTypeMap[defaultAspectRatioType] ?? '自动'),
+ ),
],
),
],
diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart
index f468321f..cba62ce2 100644
--- a/lib/utils/constants.dart
+++ b/lib/utils/constants.dart
@@ -240,3 +240,10 @@ const String danmakuOnSvg = '''
<path fill="#00AEEC" fill-rule="evenodd" d="M22.846 14.627a1 1 0 0 0-1.412.075l-5.091 5.703-2.216-2.275-.097-.086-.008-.005a1 1 0 0 0-1.322 1.493l2.963 3.041.093.083.007.005a1 1 0 0 0 1.354-.124l5.81-6.505.08-.102.005-.008a1 1 0 0 0-.166-1.295Z" clip-rule="evenodd"/>
</svg>
''';
+
+//可选默认视频比例
+const Map<int, String> aspectRatioTypeMap = {
+ 1 : "自动",
+ 2 : "裁切填充",
+ 3 : "拉伸填充",
+};
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index c5ea3322..d81c7f13 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -205,6 +205,7 @@ class SettingBoxKey {
autoUpdate = 'autoUpdate',
alwaysOntop = 'alwaysOntop',
defaultPlaySpeed = 'defaultPlaySpeed',
+ defaultAspectRatioType = 'defaultAspectRatioType',
danmakuEnhance = 'danmakuEnhance',
danmakuBorder = 'danmakuBorder',
danmakuOpacity = 'danmakuOpacity',