Skip to content

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

feat: custom button skip time and arrowKey skip time settings

Ferne04d831b0587b
diff --git a/lib/bean/dialog/dialog_helper.dart b/lib/bean/dialog/dialog_helper.dart
index 237a84fe..295659a3 100644
--- a/lib/bean/dialog/dialog_helper.dart
+++ b/lib/bean/dialog/dialog_helper.dart
@@ -182,10 +182,11 @@ class KazumiDialog {
}
}
- static void dismiss() {
+ // 在存在返回值时弹出并附带返回值
+ static void dismiss<T>({T? popWith}) {
if (observer.hasKazumiDialog && observer.kazumiDialogContext != null) {
try {
- Navigator.of(observer.kazumiDialogContext!).pop();
+ Navigator.of(observer.kazumiDialogContext!).pop(popWith);
} catch (e) {
debugPrint('Kazumi Dialog Error: Failed to dismiss dialog: $e');
}
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dart
index ef4ede01..1188d898 100644
--- a/lib/pages/player/player_controller.dart
+++ b/lib/pages/player/player_controller.dart
@@ -119,7 +119,8 @@ abstract class _PlayerController with Store {
bool lowMemoryMode = false;
bool autoPlay = true;
bool playerDebugMode = false;
- int forwardTime = 80;
+ int buttonSkipTime = 80;
+ int arrowKeySkipTime = 10;
// 播放器实时状态
bool get playerPlaying => mediaPlayer!.state.playing;
@@ -186,10 +187,17 @@ abstract class _PlayerController with Store {
getDanDanmakuByBgmBangumiID(
videoPageController.bangumiItem.id, episodeFromTitle);
mediaPlayer ??= await createVideoController(offset: offset);
+
playerSpeed =
setting.get(SettingBoxKey.defaultPlaySpeed, defaultValue: 1.0);
aspectRatioType =
setting.get(SettingBoxKey.defaultAspectRatioType, defaultValue: 1);
+
+ buttonSkipTime =
+ setting.get(SettingBoxKey.buttonSkipTime, defaultValue: 80);
+ arrowKeySkipTime =
+ setting.get(SettingBoxKey.arrowKeySkipTime, defaultValue: 10);
+
if (Utils.isDesktop()) {
volume = volume != -1 ? volume : 100;
await setVolume(volume);
@@ -482,8 +490,14 @@ abstract class _PlayerController with Store {
return await mediaPlayer!.screenshot(format: format);
}
- void setForwardTime(int time) {
- forwardTime = time;
+ void setButtonForwardTime(int time) {
+ buttonSkipTime = time;
+ setting.put(SettingBoxKey.buttonSkipTime, time);
+ }
+
+ void setArrowKeyForwardTime(int time) {
+ arrowKeySkipTime = time;
+ setting.put(SettingBoxKey.arrowKeySkipTime, time);
}
Future<void> getDanDanmakuByBgmBangumiID(
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index 0670ca50..2e0e2822 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -227,7 +227,8 @@ class _PlayerItemState extends State<PlayerItem>
if (!mounted) return;
final bool isHighMode = shaderIndex == 3;
- final bool alreadyShown = setting.get(SettingBoxKey.superResolutionWarn, defaultValue: false);
+ final bool alreadyShown =
+ setting.get(SettingBoxKey.superResolutionWarn, defaultValue: false);
if (isHighMode && !alreadyShown) {
bool confirmed = false;
@@ -249,7 +250,8 @@ class _PlayerItemState extends State<PlayerItem>
children: [
Checkbox(
value: dontAskAgain,
- onChanged: (value) => setState(() => dontAskAgain = value ?? false),
+ onChanged: (value) =>
+ setState(() => dontAskAgain = value ?? false),
),
const Text('下次不再询问'),
],
@@ -574,131 +576,127 @@ class _PlayerItemState extends State<PlayerItem>
}
Widget get videoInfoBody {
- return Observer(
- builder: (context) {
- return ListView(
- children: [
- ListTile(
- title: const Text("Source"),
- subtitle: Text(playerController.videoUrl),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(text: playerController.videoUrl),
- );
- },
- ),
- ListTile(
- title: const Text("Resolution"),
- subtitle: Text(
- '${playerController.playerWidth}x${playerController.playerHeight}'),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "Resolution\n${playerController.playerWidth}x${playerController.playerHeight}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("VideoParams"),
- subtitle: Text(playerController.playerVideoParams.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "VideoParams\n${playerController.playerVideoParams.toString()}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("AudioParams"),
- subtitle: Text(playerController.playerAudioParams.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "AudioParams\n${playerController.playerAudioParams.toString()}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("Media"),
- subtitle: Text(playerController.playerPlaylist.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text: "Media\n${playerController.playerPlaylist.toString()}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("AudioTrack"),
- subtitle: Text(playerController.playerAudioTracks.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "AudioTrack\n${playerController.playerAudioTracks.toString()}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("VideoTrack"),
- subtitle: Text(playerController.playerVideoTracks.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "VideoTrack\n${playerController.playerVideoTracks.toString()}",
- ),
- );
- },
- ),
- ListTile(
- title: const Text("AudioBitrate"),
- subtitle: Text(playerController.playerAudioBitrate.toString()),
- onTap: () {
- KazumiDialog.showToast(message: '已复制到剪贴板');
- Clipboard.setData(
- ClipboardData(
- text:
- "AudioBitrate\n${playerController.playerAudioBitrate.toString()}",
- ),
- );
- },
- ),
- ],
- );
- }
- );
+ return Observer(builder: (context) {
+ return ListView(
+ children: [
+ ListTile(
+ title: const Text("Source"),
+ subtitle: Text(playerController.videoUrl),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(text: playerController.videoUrl),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("Resolution"),
+ subtitle: Text(
+ '${playerController.playerWidth}x${playerController.playerHeight}'),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "Resolution\n${playerController.playerWidth}x${playerController.playerHeight}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("VideoParams"),
+ subtitle: Text(playerController.playerVideoParams.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "VideoParams\n${playerController.playerVideoParams.toString()}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("AudioParams"),
+ subtitle: Text(playerController.playerAudioParams.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "AudioParams\n${playerController.playerAudioParams.toString()}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("Media"),
+ subtitle: Text(playerController.playerPlaylist.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text: "Media\n${playerController.playerPlaylist.toString()}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("AudioTrack"),
+ subtitle: Text(playerController.playerAudioTracks.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "AudioTrack\n${playerController.playerAudioTracks.toString()}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("VideoTrack"),
+ subtitle: Text(playerController.playerVideoTracks.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "VideoTrack\n${playerController.playerVideoTracks.toString()}",
+ ),
+ );
+ },
+ ),
+ ListTile(
+ title: const Text("AudioBitrate"),
+ subtitle: Text(playerController.playerAudioBitrate.toString()),
+ onTap: () {
+ KazumiDialog.showToast(message: '已复制到剪贴板');
+ Clipboard.setData(
+ ClipboardData(
+ text:
+ "AudioBitrate\n${playerController.playerAudioBitrate.toString()}",
+ ),
+ );
+ },
+ ),
+ ],
+ );
+ });
}
Widget get videoDebugLogBody {
return Scaffold(
body: Padding(
padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 0),
- child: Observer(
- builder: (context) {
- return ListView.builder(
- itemCount: playerController.playerLog.length,
- itemBuilder: (context, index) {
- return Text(playerController.playerLog[index]);
- },
- );
- }
- ),
+ child: Observer(builder: (context) {
+ return ListView.builder(
+ itemCount: playerController.playerLog.length,
+ itemBuilder: (context, index) {
+ return Text(playerController.playerLog[index]);
+ },
+ );
+ }),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.copy),
@@ -1124,7 +1122,7 @@ class _PlayerItemState extends State<PlayerItem>
LogicalKeyboardKey.arrowLeft) {
int targetPosition = playerController
.currentPosition.inSeconds -
- 10;
+ playerController.arrowKeySkipTime;
if (targetPosition < 0) {
targetPosition = 0;
}
@@ -1201,7 +1199,8 @@ class _PlayerItemState extends State<PlayerItem>
playerController.seek(Duration(
seconds: playerController
.currentPosition.inSeconds +
- 10));
+ playerController
+ .arrowKeySkipTime));
playerTimer = getPlayerTimer();
} catch (e) {
KazumiLogger().log(Level.error,
@@ -1294,7 +1293,8 @@ class _PlayerItemState extends State<PlayerItem>
handleProgressBarDragStart:
handleProgressBarDragStart,
handleProgressBarDragEnd: handleProgressBarDragEnd,
- handleSuperResolutionChange: handleSuperResolutionChange,
+ handleSuperResolutionChange:
+ handleSuperResolutionChange,
animationController: animationController!,
keyboardFocus: widget.keyboardFocus,
sendDanmaku: widget.sendDanmaku,
@@ -1305,7 +1305,7 @@ class _PlayerItemState extends State<PlayerItem>
showSyncPlayRoomCreateDialog:
showSyncPlayRoomCreateDialog,
showSyncPlayEndPointSwitchDialog:
- showSyncPlayEndPointSwitchDialog,
+ showSyncPlayEndPointSwitchDialog,
disableAnimations: widget.disableAnimations,
)
: SmallestPlayerItemPanel(
@@ -1316,7 +1316,8 @@ class _PlayerItemState extends State<PlayerItem>
handleProgressBarDragStart:
handleProgressBarDragStart,
handleProgressBarDragEnd: handleProgressBarDragEnd,
- handleSuperResolutionChange: handleSuperResolutionChange,
+ handleSuperResolutionChange:
+ handleSuperResolutionChange,
animationController: animationController!,
keyboardFocus: widget.keyboardFocus,
handleHove: _handleHove,
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index 448f8384..38e31d81 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -234,7 +234,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
decoration: InputDecoration(
floatingLabelBehavior:
FloatingLabelBehavior.never, // 控制label的显示方式
- labelText: playerController.forwardTime.toString(),
+ labelText: playerController.buttonSkipTime.toString(),
),
onChanged: (value) {
input = value;
@@ -252,7 +252,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
TextButton(
onPressed: () async {
if (input != "") {
- playerController.setForwardTime(int.parse(input));
+ playerController.setButtonForwardTime(int.parse(input));
KazumiDialog.dismiss();
} else {
KazumiDialog.dismiss();
@@ -305,7 +305,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
),
onPressed: () {
playerController.seek(playerController.currentPosition +
- Duration(seconds: playerController.forwardTime));
+ Duration(seconds: playerController.buttonSkipTime));
},
),
),
diff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dart
index 20c7fd4d..21864a84 100644
--- a/lib/pages/player/smallest_player_item_panel.dart
+++ b/lib/pages/player/smallest_player_item_panel.dart
@@ -87,7 +87,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
decoration: InputDecoration(
floatingLabelBehavior:
FloatingLabelBehavior.never, // 控制label的显示方式
- labelText: playerController.forwardTime.toString(),
+ labelText: playerController.buttonSkipTime.toString(),
),
onChanged: (value) {
input = value;
@@ -105,7 +105,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
TextButton(
onPressed: () async {
if (input != "") {
- playerController.setForwardTime(int.parse(input));
+ playerController.setButtonForwardTime(int.parse(input));
KazumiDialog.dismiss();
} else {
KazumiDialog.dismiss();
@@ -158,7 +158,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
),
onPressed: () {
playerController.seek(playerController.currentPosition +
- Duration(seconds: playerController.forwardTime));
+ Duration(seconds: playerController.buttonSkipTime));
},
),
),
diff --git a/lib/pages/settings/player_settings.dart b/lib/pages/settings/player_settings.dart
index 3c0e9194..fe218bb8 100644
--- a/lib/pages/settings/player_settings.dart
+++ b/lib/pages/settings/player_settings.dart
@@ -1,12 +1,16 @@
import 'dart:io';
import 'package:flutter/material.dart';
+import 'package:flutter/services.dart' show FilteringTextInputFormatter;
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:hive/hive.dart';
import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/pages/player/player_controller.dart';
import 'package:kazumi/utils/constants.dart';
+import 'package:kazumi/utils/logger.dart';
import 'package:kazumi/utils/storage.dart';
import 'package:card_settings_ui/card_settings_ui.dart';
+import 'package:logger/logger.dart';
class PlayerSettingsPage extends StatefulWidget {
const PlayerSettingsPage({super.key});
@@ -27,6 +31,8 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
late bool privateMode;
late bool playerDebugMode;
late bool playerDisableAnimations;
+ late int playerButtonSkipTime;
+ late int playerArrowKeySkipTime;
final MenuController menuController = MenuController();
@override
@@ -49,6 +55,11 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
setting.get(SettingBoxKey.playerDebugMode, defaultValue: false);
playerDisableAnimations =
setting.get(SettingBoxKey.playerDisableAnimations, defaultValue: false);
+
+ playerButtonSkipTime =
+ setting.get(SettingBoxKey.buttonSkipTime, defaultValue: 80);
+ playerArrowKeySkipTime =
+ setting.get(SettingBoxKey.arrowKeySkipTime, defaultValue: 10);
}
void onBackPressed(BuildContext context) {
@@ -72,6 +83,73 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
});
}
+ Future<void> updateButtonSkipTime() async {
+ final int? newButtonSkipTime = await _showSkipTimeChangeDialog(
+ title: '顶部按钮快进时长', initialValue: playerButtonSkipTime.toString());
+ print('新设置的顶部按钮快进时长: $newButtonSkipTime');
+
+ if (newButtonSkipTime != null &&
+ newButtonSkipTime != playerButtonSkipTime) {
+ setting.put(SettingBoxKey.buttonSkipTime, newButtonSkipTime);
+ setState(() {
+ playerButtonSkipTime = newButtonSkipTime;
+ });
+ }
+ }
+
+ Future<int?> _showSkipTimeChangeDialog(
+ {required String title, required String initialValue}) async {
+ return KazumiDialog.show<int>(builder: (context) {
+ String input = "";
+ return AlertDialog(
+ title: Text(title),
+ content: StatefulBuilder(
+ builder: (BuildContext context, StateSetter setState) {
+ return TextField(
+ inputFormatters: [
+ FilteringTextInputFormatter.digitsOnly, // 只允许输入数字
+ ],
+ decoration: InputDecoration(
+ floatingLabelBehavior:
+ FloatingLabelBehavior.never, // 控制label的显示方式
+ labelText: initialValue,
+ ),
+ onChanged: (value) {
+ input = value;
+ },
+ );
+ }),
+ actions: <Widget>[
+ TextButton(
+ onPressed: () => KazumiDialog.dismiss(),
+ child: Text(
+ '取消',
+ style: TextStyle(color: Theme.of(context).colorScheme.outline),
+ ),
+ ),
+ TextButton(
+ onPressed: () async {
+ final int? newValue = int.tryParse(input);
+
+ if (newValue == null) {
+ KazumiDialog.showToast(message: '请输入数字');
+ return;
+ }
+
+ if (newValue <= 0) {
+ KazumiDialog.showToast(message: '请输入大于0的数字');
+ return;
+ }
+ // 以新设置的值弹出
+ KazumiDialog.dismiss(popWith: newValue);
+ },
+ child: const Text('确定'),
+ ),
+ ],
+ );
+ });
+ }
+
@override
Widget build(BuildContext context) {
return PopScope(
@@ -207,6 +285,37 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
},
),
),
+ SettingsTile.navigation(
+ description: Slider(
+ value: playerArrowKeySkipTime.toDouble(),
+ min: 0,
+ max: 15,
+ divisions: 15,
+ label: '$playerArrowKeySkipTime秒',
+ onChanged: (value) {
+ final newArrowKeySkipTime = value.toInt();
+ print('新设置的方向键快进/快退时长: $newArrowKeySkipTime');
+
+ if (value != playerArrowKeySkipTime) {
+ setting.put(SettingBoxKey.arrowKeySkipTime,
+ newArrowKeySkipTime);
+ setState(() {
+ playerArrowKeySkipTime = newArrowKeySkipTime;
+ });
+ }
+ },
+ ),
+ title: const Text('左右方向键的快进/快退秒数'),
+ value: Text('$playerArrowKeySkipTime 秒'),
+ ),
+ SettingsTile.navigation(
+ onPressed: (_) async {
+ await updateButtonSkipTime();
+ },
+ title: const Text('跳过时长'),
+ description: const Text('顶栏跳过按钮的秒数'),
+ value: Text('$playerButtonSkipTime 秒'),
+ ),
SettingsTile.navigation(
onPressed: (_) async {
if (menuController.isOpen) {
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index 11d845ab..238a72d7 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -212,6 +212,8 @@ class SettingBoxKey {
alwaysOntop = 'alwaysOntop',
defaultPlaySpeed = 'defaultPlaySpeed',
defaultAspectRatioType = 'defaultAspectRatioType',
+ buttonSkipTime = 'buttonSkipTime',
+ arrowKeySkipTime = 'arrowKeySkipTime',
danmakuEnhance = 'danmakuEnhance',
danmakuBorder = 'danmakuBorder',
danmakuOpacity = 'danmakuOpacity',
diff --git a/pubspec.lock b/pubspec.lock
index 35879b60..d1155d2b 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1782,4 +1782,4 @@ packages:
version: "3.1.3"
sdks:
dart: ">=3.8.0 <4.0.0"
- flutter: ">=3.35.6"
+ flutter: ">=3.35.6"
\ No newline at end of file
diff --git a/pubspec.yaml b/pubspec.yaml
index ac9423a1..c8351fa2 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -238,4 +238,4 @@ flutter:
# weight: 700
#
# For details regarding fonts from package dependencies,
- # see https://flutter.dev/custom-fonts/#from-packages
+ # see https://flutter.dev/custom-fonts/#from-packages
\ No newline at end of file