Skip to content

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

feat(android): mpv vo options

Predidit681adfafbfb4
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dart
index eeb96842..2d0b90cd 100644
--- a/lib/pages/player/player_controller.dart
+++ b/lib/pages/player/player_controller.dart
@@ -112,7 +112,8 @@ abstract class _PlayerController with Store {
/// 视频超分
/// 1. OFF
- /// 2. Anime4K
+ /// 2. Anime4K Efficiency
+ /// 3. Anime4K Quality
@observable
int superResolutionType = 1;
@@ -406,21 +407,37 @@ abstract class _PlayerController with Store {
AudioTrack.auto(),
);
- // Android 14 及以上使用基于 Vulkan 的 MPV GPU-NEXT 视频输出,着色器性能更好
- // GPU-NEXT 需要 Vulkan 1.2 支持
- // 避免 Android 14 及以下设备上部分机型 Vulkan 支持不佳导致的黑屏问题
- bool enableGPUNext = false;
+ String? videoRenderer;
if (Platform.isAndroid) {
- final int androidSdkVersion = await Utils.getAndroidSdkVersion();
- if (androidSdkVersion >= 34) {
- enableGPUNext = true;
+ final String androidVideoRenderer = setting.get(
+ SettingBoxKey.androidVideoRenderer,
+ defaultValue: 'auto'
+ );
+
+ if (androidVideoRenderer == 'auto') {
+ // Android 14 及以上使用基于 Vulkan 的 MPV GPU-NEXT 视频输出,着色器性能更好
+ // GPU-NEXT 需要 Vulkan 1.2 支持
+ // 避免 Android 14 及以下设备上部分机型 Vulkan 支持不佳导致的黑屏问题
+ final int androidSdkVersion = await Utils.getAndroidSdkVersion();
+ if (androidSdkVersion >= 34) {
+ videoRenderer = 'gpu-next';
+ } else {
+ videoRenderer = 'gpu';
+ }
+ } else {
+ videoRenderer = androidVideoRenderer;
}
}
+ if (videoRenderer == 'mediacodec_embed') {
+ hardwareDecoder = 'mediacodec';
+ superResolutionType = 1;
+ }
+
videoController ??= VideoController(
mediaPlayer!,
configuration: VideoControllerConfiguration(
- vo: enableGPUNext ? 'gpu-next' : null,
+ vo: videoRenderer,
enableHardwareAcceleration: hAenable,
hwdec: hAenable ? hardwareDecoder : 'no',
androidAttachSurfaceAfterVideoParameters: false,
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index 6b7506b0..f9b85060 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -31,9 +31,6 @@ import 'package:mobx/mobx.dart' as mobx;
import 'package:kazumi/pages/my/my_controller.dart';
import 'package:saver_gallery/saver_gallery.dart';
-
-
-
class PlayerItem extends StatefulWidget {
const PlayerItem({
super.key,
@@ -79,7 +76,6 @@ class _PlayerItemState extends State<PlayerItem>
late List<String> keyboardActionsNeedLongPress;
late Map<String, void Function()> keyboardActions;
-
// 1. 在看
// 2. 想看
// 3. 搁置
@@ -147,7 +143,7 @@ class _PlayerItemState extends State<PlayerItem>
});
}
- void _initKeyboardActions(){
+ void _initKeyboardActions() {
//需要实现长按的功能列表。
keyboardActionsNeedLongPress = ["forward"];
//快捷键功能对应表
@@ -173,17 +169,20 @@ class _PlayerItemState extends State<PlayerItem>
// 开始对应长按功能
// 如需对应长按功能,例如对功能'func'对应长按,请分别添加'funcRepeat'和'funcUp'。
'forwardRepeat': () async => handleShortcutForwardRepeat(),
- 'forwardUp' : () async => handleShortcutForwardUp(),
+ 'forwardUp': () async => handleShortcutForwardUp(),
};
}
+
//初始化播放器菜单
- void _initPlayerMenu(){
+ void _initPlayerMenu() {
Utils.initPlayerMenu(keyboardActions);
}
+
//销毁播放器菜单
- void _disposePlayerMenu(){
+ void _disposePlayerMenu() {
Utils.disposePlayerMenu();
}
+
//快捷键按下
bool handleShortcutDown(String keyLabel) {
for (final entry in keyboardShortcuts.entries) {
@@ -199,13 +198,14 @@ class _PlayerItemState extends State<PlayerItem>
}
return false;
}
+
// 快捷键长按
bool handleShortcutLongPress(String keyLabel, String mode) {
- for (final func in keyboardActionsNeedLongPress){
+ for (final func in keyboardActionsNeedLongPress) {
final keys = keyboardShortcuts[func];
if (keys?.contains(keyLabel) == true) {
final action = keyboardActions[func + mode];
- if (action != null){
+ if (action != null) {
action();
return true;
}
@@ -215,15 +215,19 @@ class _PlayerItemState extends State<PlayerItem>
}
//上一集下一集动作
- Future<void> handlePreNextEpisode(String direction) async{
+ Future<void> handlePreNextEpisode(String direction) async {
if (videoPageController.loading) return;
final currentRoad = videoPageController.currentRoad;
final episodes = videoPageController.roadList[currentRoad].data;
int targetEpisode;
- if (direction == 'next'){targetEpisode = videoPageController.currentEpisode + 1;}
- else if (direction == 'prev') {targetEpisode = videoPageController.currentEpisode - 1;}
- else {return;}
-
+ if (direction == 'next') {
+ targetEpisode = videoPageController.currentEpisode + 1;
+ } else if (direction == 'prev') {
+ targetEpisode = videoPageController.currentEpisode - 1;
+ } else {
+ return;
+ }
+
if (targetEpisode > episodes.length) {
KazumiDialog.showToast(message: '已经是最新一集');
return;
@@ -232,8 +236,9 @@ class _PlayerItemState extends State<PlayerItem>
KazumiDialog.showToast(message: '已经是第一集');
return;
}
-
- final identifier = videoPageController.roadList[currentRoad].identifier[targetEpisode - 1];
+
+ final identifier =
+ videoPageController.roadList[currentRoad].identifier[targetEpisode - 1];
KazumiDialog.showToast(message: '正在加载$identifier');
widget.changeEpisode(targetEpisode, currentRoad: currentRoad);
}
@@ -255,16 +260,19 @@ class _PlayerItemState extends State<PlayerItem>
KazumiLogger().e('PlayerController: seek failed', error: e);
}
}
+
// 快进快捷键动作
Future<void> handleShortcutForwardDown() async {
lastPlayerSpeed = playerController.playerSpeed;
}
+
Future<void> handleShortcutForwardRepeat() async {
if (playerController.playerSpeed < 2.0) {
playerController.showPlaySpeed = true;
setPlaybackSpeed(2.0);
}
}
+
Future<void> handleShortcutForwardUp() async {
int skipTime = playerController.arrowKeySkipTime;
int current = playerController.currentPosition.inSeconds;
@@ -288,21 +296,18 @@ class _PlayerItemState extends State<PlayerItem>
}
//全屏快捷键动作
- void handleShortcutFullscreen(){
+ void handleShortcutFullscreen() {
if (!videoPageController.isPip) handleFullscreen();
}
-
+
//退出全屏快捷键动作
- void handleShortcutExitFullscreen(){
- if (videoPageController.isFullscreen &&
- !Utils.isTablet()) {
+ void handleShortcutExitFullscreen() {
+ if (videoPageController.isFullscreen && !Utils.isTablet()) {
try {
- playerController.danmakuController
- .clear();
+ playerController.danmakuController.clear();
} catch (_) {}
Utils.exitFullScreen();
- videoPageController.isFullscreen =
- !videoPageController.isFullscreen;
+ videoPageController.isFullscreen = !videoPageController.isFullscreen;
} else if (!Platform.isMacOS) {
playerController.pause();
windowManager.hide();
@@ -347,10 +352,11 @@ class _PlayerItemState extends State<PlayerItem>
mouseScrollerTimer = null;
});
}
-
+
//跳过指定秒数
Future<void> skipOP() async {
- await playerController.seek(playerController.currentPosition + Duration(seconds: playerController.buttonSkipTime));
+ await playerController.seek(playerController.currentPosition +
+ Duration(seconds: playerController.buttonSkipTime));
}
void handleDanmaku() {
@@ -404,7 +410,7 @@ class _PlayerItemState extends State<PlayerItem>
playerTimer?.cancel();
playerTimer = getPlayerTimer();
}
-
+
//截图
Future<void> handleScreenshot() async {
KazumiDialog.showToast(message: '截图中...');
@@ -440,6 +446,31 @@ class _PlayerItemState extends State<PlayerItem>
Future<void> handleSuperResolutionChange(int shaderIndex) async {
if (!mounted) return;
+ // mediacodec_embed 不支持超分辨率
+ if (Platform.isAndroid && shaderIndex != 1) {
+ final String androidVideoRenderer =
+ setting.get(SettingBoxKey.androidVideoRenderer, defaultValue: 'auto');
+
+ if (androidVideoRenderer == 'mediacodec_embed') {
+ await KazumiDialog.show(builder: (context) {
+ return AlertDialog(
+ title: const Text('兼容性提示'),
+ content: const Text('MediaCodec 渲染器不支持超分辨率功能。\n\n'
+ '如需使用超分辨率,请在播放设置中将视频渲染器切换为 gpu 或 gpu-next。'),
+ actions: [
+ TextButton(
+ onPressed: () {
+ KazumiDialog.dismiss();
+ },
+ child: const Text('确定'),
+ ),
+ ],
+ );
+ });
+ return;
+ }
+ }
+
final bool isHighMode = shaderIndex == 3;
final bool alreadyShown =
setting.get(SettingBoxKey.superResolutionWarn, defaultValue: false);
@@ -537,8 +568,7 @@ class _PlayerItemState extends State<PlayerItem>
await playerController.setPlaybackSpeed(speed);
}
-
- Future<void> handleSpeedChange(String type) async{
+ Future<void> handleSpeedChange(String type) async {
try {
final currentSpeed = playerController.playerSpeed;
int index = defaultPlaySpeedList.indexOf(currentSpeed);
@@ -549,8 +579,7 @@ class _PlayerItemState extends State<PlayerItem>
} else {
KazumiDialog.showToast(message: '已达倍速上限');
}
- }
- else if (type == "down") {
+ } else if (type == "down") {
if (index > 0) {
index--;
setPlaybackSpeed(defaultPlaySpeedList[index]);
@@ -713,7 +742,8 @@ class _PlayerItemState extends State<PlayerItem>
videoPageController.currentEpisode <
videoPageController
.roadList[videoPageController.currentRoad].data.length &&
- !videoPageController.loading && autoPlayNext) {
+ !videoPageController.loading &&
+ autoPlayNext) {
KazumiDialog.showToast(
message:
'正在加载${videoPageController.roadList[videoPageController.currentRoad].identifier[videoPageController.currentEpisode]}');
@@ -1404,17 +1434,22 @@ class _PlayerItemState extends State<PlayerItem>
autofocus: true,
onKeyEvent: (focusNode, KeyEvent event) {
bool handled = false;
- final keyLabel = event.logicalKey.keyLabel.isNotEmpty
- ? event.logicalKey.keyLabel
- : event.logicalKey.debugName ?? '';
+ final keyLabel =
+ event.logicalKey.keyLabel.isNotEmpty
+ ? event.logicalKey.keyLabel
+ : event.logicalKey.debugName ?? '';
if (event is KeyDownEvent) {
handled = handleShortcutDown(keyLabel);
} else if (event is KeyRepeatEvent) {
- handled = handleShortcutLongPress(keyLabel,"Repeat");
+ handled =
+ handleShortcutLongPress(keyLabel, "Repeat");
} else if (event is KeyUpEvent) {
- handled = handleShortcutLongPress(keyLabel,"Up");
+ handled =
+ handleShortcutLongPress(keyLabel, "Up");
}
- return handled ? KeyEventResult.handled : KeyEventResult.ignored;
+ return handled
+ ? KeyEventResult.handled
+ : KeyEventResult.ignored;
},
child: const PlayerItemSurface())),
(playerController.isBuffering ||
@@ -1488,7 +1523,9 @@ class _PlayerItemState extends State<PlayerItem>
strokeWidth: _border ? 1.5 : 0.0,
fontWeight: _danmakuFontWeight,
massiveMode: _massiveMode,
- fontFamily: _danmakuUseSystemFont ? null : customAppFontFamily,
+ fontFamily: _danmakuUseSystemFont
+ ? null
+ : customAppFontFamily,
),
),
),
@@ -1518,7 +1555,8 @@ class _PlayerItemState extends State<PlayerItem>
showSyncPlayRoomCreateDialog,
showSyncPlayEndPointSwitchDialog:
showSyncPlayEndPointSwitchDialog,
- showDanmakuDestinationPickerAndSend: widget.showDanmakuDestinationPickerAndSend,
+ showDanmakuDestinationPickerAndSend:
+ widget.showDanmakuDestinationPickerAndSend,
pauseForTimedShutdown: widget.pauseForTimedShutdown,
disableAnimations: widget.disableAnimations,
handleScreenShot: handleScreenshot,
diff --git a/lib/pages/settings/player_settings.dart b/lib/pages/settings/player_settings.dart
index 96fec577..058827c3 100644
--- a/lib/pages/settings/player_settings.dart
+++ b/lib/pages/settings/player_settings.dart
@@ -193,6 +193,15 @@ class _PlayerSettingsPageState extends State<PlayerSettingsPage> {
title: Text('硬件解码器', style: TextStyle(fontFamily: fontFamily)),
description: Text('仅在硬件解码启用时生效', style: TextStyle(fontFamily: fontFamily)),
),
+ if (Platform.isAndroid) ...[
+ SettingsTile.navigation(
+ onPressed: (_) async {
+ await Modular.to.pushNamed('/settings/player/renderer');
+ },
+ title: Text('视频渲染器', style: TextStyle(fontFamily: fontFamily)),
+ description: Text('选择视频输出方式', style: TextStyle(fontFamily: fontFamily)),
+ ),
+ ],
SettingsTile.switchTile(
onToggle: (value) async {
lowMemoryMode = value ?? !lowMemoryMode;
diff --git a/lib/pages/settings/renderer_settings.dart b/lib/pages/settings/renderer_settings.dart
new file mode 100644
index 00000000..5af434b5
--- /dev/null
+++ b/lib/pages/settings/renderer_settings.dart
@@ -0,0 +1,58 @@
+import 'package:flutter/material.dart';
+import 'package:hive_ce/hive.dart';
+import 'package:kazumi/bean/appbar/sys_app_bar.dart';
+import 'package:kazumi/utils/storage.dart';
+import 'package:kazumi/utils/constants.dart';
+import 'package:card_settings_ui/card_settings_ui.dart';
+
+class RendererSettings extends StatefulWidget {
+ const RendererSettings({super.key});
+
+ @override
+ State<RendererSettings> createState() => _RendererSettingsState();
+}
+
+class _RendererSettingsState extends State<RendererSettings> {
+ late final Box setting = GStorage.setting;
+ late final ValueNotifier<String> renderer = ValueNotifier<String>(
+ setting.get(SettingBoxKey.androidVideoRenderer, defaultValue: 'auto'),
+ );
+
+ @override
+ Widget build(BuildContext context) {
+ final fontFamily = Theme.of(context).textTheme.bodyMedium?.fontFamily;
+ return Scaffold(
+ appBar: const SysAppBar(
+ title: Text('视频渲染器'),
+ ),
+ body: SettingsList(
+ maxWidth: 1000,
+ sections: [
+ SettingsSection(
+ title: Text('选择合适的渲染器以获得最佳播放体验',
+ style: TextStyle(fontFamily: fontFamily)),
+ tiles: androidVideoRenderersList.entries
+ .map((e) => SettingsTile<String>.radioTile(
+ title:
+ Text(e.key, style: TextStyle(fontFamily: fontFamily)),
+ description: Text(e.value,
+ style: TextStyle(fontFamily: fontFamily)),
+ radioValue: e.key,
+ groupValue: renderer.value,
+ onChanged: (String? value) {
+ if (value != null) {
+ setting.put(
+ SettingBoxKey.androidVideoRenderer, value);
+ setState(() {
+ renderer.value = value;
+ });
+ }
+ },
+ ))
+ .toList(),
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/lib/pages/settings/settings_module.dart b/lib/pages/settings/settings_module.dart
index 703cdeab..474b4527 100644
--- a/lib/pages/settings/settings_module.dart
+++ b/lib/pages/settings/settings_module.dart
@@ -8,6 +8,7 @@ import 'package:kazumi/pages/settings/theme_settings_page.dart';
import 'package:kazumi/pages/settings/player_settings.dart';
import 'package:kazumi/pages/settings/displaymode_settings.dart';
import 'package:kazumi/pages/settings/decoder_settings.dart';
+import 'package:kazumi/pages/settings/renderer_settings.dart';
import 'package:kazumi/pages/settings/super_resolution_settings.dart';
import 'package:kazumi/pages/settings/proxy/proxy_module.dart';
import 'package:kazumi/pages/webdav_editor/webdav_module.dart';
@@ -26,6 +27,7 @@ class SettingsModule extends Module {
r.child("/keyboard", child: (_) => const KeyboardSettingsPage());
r.child("/player", child: (_) => const PlayerSettingsPage());
r.child("/player/decoder", child: (_) => const DecoderSettings());
+ r.child("/player/renderer", child: (_) => const RendererSettings());
r.child("/interface", child: (_) => const InterfaceSettingsPage());
r.module("/proxy", module: ProxyModule());
r.child("/player/super", child: (_) => const SuperResolutionSettings());
diff --git a/lib/pages/settings/super_resolution_settings.dart b/lib/pages/settings/super_resolution_settings.dart
index 0abf870d..acdeb610 100644
--- a/lib/pages/settings/super_resolution_settings.dart
+++ b/lib/pages/settings/super_resolution_settings.dart
@@ -40,7 +40,7 @@ class _SuperResolutionSettingsState extends State<SuperResolutionSettings> {
sections: [
SettingsSection(
title: Text(
- '超分辨率需要启用硬件解码, 若启用硬件解码后仍然不生效, 尝试切换硬件解码器为 auto-copy', style: TextStyle(fontFamily: fontFamily)),
+ '超分辨率需要启用硬件解码, 若启用硬件解码后仍然不生效, 尝试切换视频渲染器为 gpu', style: TextStyle(fontFamily: fontFamily)),
tiles: [
SettingsTile<String>.radioTile(
title: Text("OFF", style: TextStyle(fontFamily: fontFamily)),
diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart
index 04c14ade..ee4a0b95 100644
--- a/lib/utils/constants.dart
+++ b/lib/utils/constants.dart
@@ -124,6 +124,14 @@ const Map<String, String> hardwareDecodersList = {
'rkmpp': 'Rockchip MPP (仅部分Rockchip芯片)',
};
+/// Android 可选视频渲染器
+const Map<String, String> androidVideoRenderersList = {
+ 'auto': '自动选择',
+ 'gpu': '基于 OpenGL, 通用和稳健的选项',
+ 'gpu-next': '基于 Vulkan, 在新设备上表现最好',
+ 'mediacodec_embed': '功耗最低,不支持超分辨率',
+};
+
/// 超分辨率滤镜
const List<String> mpvAnime4KShaders = [
'Anime4K_Clamp_Highlights.glsl',
diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart
index 37fcef2b..f69c946c 100644
--- a/lib/utils/storage.dart
+++ b/lib/utils/storage.dart
@@ -318,6 +318,7 @@ class SettingBoxKey {
playerDebugMode = 'playerDebugMode',
syncPlayEndPoint = 'syncPlayEndPoint',
androidEnableOpenSLES = 'androidEnableOpenSLES',
+ androidVideoRenderer = 'androidVideoRenderer',
defaultSuperResolutionType = 'defaultSuperResolutionType',
superResolutionWarn = 'superResolutionWarn',
playerDisableAnimations = 'playerDisableAnimations',