Skip to content

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

refactor(player): improve screenshot feedback

Predidit1e30fb0903b9
diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dart
index e58ac878..c3e688d0 100644
--- a/lib/pages/player/player_item.dart
+++ b/lib/pages/player/player_item.dart
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
import 'package:kazumi/pages/player/player_item_panel.dart';
import 'package:kazumi/pages/player/player_panel_hold.dart';
+import 'package:kazumi/pages/player/player_screenshot_feedback_overlay.dart';
import 'package:kazumi/pages/player/smallest_player_item_panel.dart';
import 'package:kazumi/utils/constants.dart';
import 'package:kazumi/services/logging/logger.dart';
@@ -71,10 +72,7 @@ class PlayerItem extends StatefulWidget {
}
class _PlayerItemState extends State<PlayerItem>
- with
- WindowListener,
- WidgetsBindingObserver,
- SingleTickerProviderStateMixin {
+ with WindowListener, WidgetsBindingObserver, TickerProviderStateMixin {
Box setting = GStorage.setting;
late final PlayerController playerController;
final VideoPageController videoPageController =
@@ -132,8 +130,9 @@ class _PlayerItemState extends State<PlayerItem>
double lastVolume = 0;
- // 过渡动画控制器
- AnimationController? animationController;
+ late final AnimationController _panelVisibilityController;
+ late final AnimationController _screenshotFeedbackController;
+ late final Animation<double> _screenshotFeedbackAnimation;
double lastPlayerSpeed = 1.0;
int episodeNum = 0;
@@ -590,7 +589,7 @@ class _PlayerItemState extends State<PlayerItem>
//截图
Future<void> handleScreenshot() async {
- KazumiDialog.showToast(message: '截图中...');
+ _playScreenshotFeedback();
try {
Uint8List? screenshot = await playerController.screenshotPng();
@@ -608,9 +607,7 @@ class _PlayerItemState extends State<PlayerItem>
fileName: DateTime.timestamp().millisecondsSinceEpoch.toString(),
skipIfExists: false,
);
- if (result.isSuccess) {
- KazumiDialog.showToast(message: '截图保存到相簿成功');
- } else {
+ if (!result.isSuccess) {
KazumiDialog.showToast(message: '截图保存失败:${result.errorMessage}');
}
} catch (e) {
@@ -618,6 +615,13 @@ class _PlayerItemState extends State<PlayerItem>
}
}
+ void _playScreenshotFeedback() {
+ if (!mounted) {
+ return;
+ }
+ _screenshotFeedbackController.forward(from: 0);
+ }
+
// 启用超分辨率(质量档)时弹出提示
Future<void> handleSuperResolutionChange(int shaderIndex) async {
if (!mounted) return;
@@ -730,7 +734,7 @@ class _PlayerItemState extends State<PlayerItem>
playerController.panel.canHidePlayerPanel && _playerPanelHolds.isEmpty;
void showVideoController({bool restartHideTimer = true}) {
- animationController?.forward();
+ _panelVisibilityController.forward();
playerController.panel.showVideoController = true;
if (restartHideTimer && _canHidePlayerPanel) {
_startHideTimer();
@@ -745,7 +749,7 @@ class _PlayerItemState extends State<PlayerItem>
if (!_canHidePlayerPanel) {
return;
}
- animationController?.reverse();
+ _panelVisibilityController.reverse();
_cancelHideTimer();
playerController.panel.showVideoController = false;
}
@@ -950,8 +954,8 @@ class _PlayerItemState extends State<PlayerItem>
// 音量相关
if (!playerController.panel.volumeSeeking) {
if (isDesktop()) {
- playerController.playback.applyExternalVolume(
- playerController.playback.playerVolume);
+ playerController.playback
+ .applyExternalVolume(playerController.playback.playerVolume);
}
}
// 亮度相关
@@ -1585,10 +1589,18 @@ class _PlayerItemState extends State<PlayerItem>
unawaited(_updateAndroidPIPActions(force: true));
}
WidgetsBinding.instance.addObserver(this);
- animationController ??= AnimationController(
+ _panelVisibilityController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
+ _screenshotFeedbackController = AnimationController(
+ duration: const Duration(milliseconds: 420),
+ vsync: this,
+ );
+ _screenshotFeedbackAnimation = CurvedAnimation(
+ parent: _screenshotFeedbackController,
+ curve: Curves.linear,
+ );
webDavEnable = setting.get(SettingBoxKey.webDavEnable, defaultValue: false);
webDavEnableHistory =
setting.get(SettingBoxKey.webDavEnableHistory, defaultValue: false);
@@ -1646,8 +1658,8 @@ class _PlayerItemState extends State<PlayerItem>
hideTimer?.cancel();
mouseScrollerTimer?.cancel();
hideVolumeUITimer?.cancel();
- animationController?.dispose();
- animationController = null;
+ _panelVisibilityController.dispose();
+ _screenshotFeedbackController.dispose();
_disposePlayerMenu();
if (Platform.isAndroid) {
unawaited(_syncAndroidPIPPlayerPageState(false));
@@ -1683,7 +1695,7 @@ class _PlayerItemState extends State<PlayerItem>
displayVideoController();
} else {
if (!playerController.panel.showVideoController) {
- animationController?.forward();
+ _panelVisibilityController.forward();
playerController.panel.showVideoController = true;
}
}
@@ -1811,6 +1823,11 @@ class _PlayerItemState extends State<PlayerItem>
),
),
),
+ Positioned.fill(
+ child: PlayerScreenshotFeedbackOverlay(
+ animation: _screenshotFeedbackAnimation,
+ ),
+ ),
// 播放器控制面板
(needFullPanel(context))
? PlayerItemPanel(
@@ -1827,7 +1844,8 @@ class _PlayerItemState extends State<PlayerItem>
handleSuperResolutionChange:
handleSuperResolutionChange,
handlePreNextEpisode: handlePreNextEpisode,
- animationController: animationController!,
+ panelVisibilityController:
+ _panelVisibilityController,
keyboardFocus: widget.keyboardFocus,
sendDanmaku: widget.sendDanmaku,
acquirePlayerPanelHold: acquirePlayerPanelHold,
@@ -1855,7 +1873,8 @@ class _PlayerItemState extends State<PlayerItem>
handleProgressBarDragEnd: handleProgressBarDragEnd,
handleSuperResolutionChange:
handleSuperResolutionChange,
- animationController: animationController!,
+ panelVisibilityController:
+ _panelVisibilityController,
keyboardFocus: widget.keyboardFocus,
acquirePlayerPanelHold: acquirePlayerPanelHold,
handleDanmaku: handleDanmaku,
@@ -1944,7 +1963,8 @@ class _PlayerItemState extends State<PlayerItem>
.invalidatePreciseVolume();
}
final double baseVolume = playerController
- .playback.preciseVolume >= 0
+ .playback.preciseVolume >=
+ 0
? playerController.playback.preciseVolume
: playerController.playback.volume;
final double level = (totalHeight) * 0.03;
diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dart
index 87810f33..7d03cddf 100644
--- a/lib/pages/player/player_item_panel.dart
+++ b/lib/pages/player/player_item_panel.dart
@@ -36,7 +36,7 @@ class PlayerItemPanel extends StatefulWidget {
required this.handleProgressBarDragStart,
required this.handleProgressBarDragEnd,
required this.handleSuperResolutionChange,
- required this.animationController,
+ required this.panelVisibilityController,
required this.toggleMenu,
required this.keyboardFocus,
required this.sendDanmaku,
@@ -62,7 +62,7 @@ class PlayerItemPanel extends StatefulWidget {
final void Function(ThumbDragDetails details) handleProgressBarDragStart;
final void Function() handleProgressBarDragEnd;
final Future<void> Function(int shaderIndex) handleSuperResolutionChange;
- final AnimationController animationController;
+ final AnimationController panelVisibilityController;
final FocusNode keyboardFocus;
final PlayerPanelHold Function() acquirePlayerPanelHold;
final void Function() handleDanmaku;
@@ -303,21 +303,21 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
begin: const Offset(0.0, -1.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
bottomOffsetAnimation = Tween<Offset>(
begin: const Offset(0.0, 1.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
leftOffsetAnimation = Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);
diff --git a/lib/pages/player/player_screenshot_feedback_overlay.dart b/lib/pages/player/player_screenshot_feedback_overlay.dart
new file mode 100644
index 00000000..9fae6a3e
--- /dev/null
+++ b/lib/pages/player/player_screenshot_feedback_overlay.dart
@@ -0,0 +1,155 @@
+import 'package:flutter/material.dart';
+
+class PlayerScreenshotFeedbackOverlay extends StatelessWidget {
+ const PlayerScreenshotFeedbackOverlay({
+ super.key,
+ required this.animation,
+ });
+
+ final Animation<double> animation;
+
+ @override
+ Widget build(BuildContext context) {
+ return IgnorePointer(
+ child: AnimatedBuilder(
+ animation: animation,
+ builder: (context, child) {
+ final value = animation.value;
+ if (value == 0.0) {
+ return const SizedBox.shrink();
+ }
+
+ final dimOpacity =
+ 0.12 * _pulse(value, begin: 0.0, peak: 0.18, end: 0.62);
+ final frameOpacity = 0.90 *
+ _interval(value, begin: 0.0, end: 0.14, curve: Curves.easeOut) *
+ (1 -
+ _interval(
+ value,
+ begin: 0.58,
+ end: 1.0,
+ curve: Curves.easeOutCubic,
+ ));
+ final frameProgress = _interval(
+ value,
+ begin: 0.0,
+ end: 0.68,
+ curve: Curves.easeOutCubic,
+ );
+
+ return Stack(
+ fit: StackFit.expand,
+ children: [
+ ColoredBox(
+ color: Colors.black.withValues(alpha: dimOpacity),
+ ),
+ CustomPaint(
+ painter: _ScreenshotFramePainter(
+ opacity: frameOpacity,
+ progress: frameProgress,
+ ),
+ ),
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ static double _interval(
+ double value, {
+ required double begin,
+ required double end,
+ required Curve curve,
+ }) {
+ if (value <= begin) {
+ return 0.0;
+ }
+ if (value >= end) {
+ return 1.0;
+ }
+ return curve.transform((value - begin) / (end - begin));
+ }
+
+ static double _pulse(
+ double value, {
+ required double begin,
+ required double peak,
+ required double end,
+ }) {
+ if (value <= begin || value >= end) {
+ return 0.0;
+ }
+ if (value <= peak) {
+ return _interval(
+ value,
+ begin: begin,
+ end: peak,
+ curve: Curves.easeOutCubic,
+ );
+ }
+ return 1 -
+ _interval(
+ value,
+ begin: peak,
+ end: end,
+ curve: Curves.easeOutCubic,
+ );
+ }
+}
+
+class _ScreenshotFramePainter extends CustomPainter {
+ const _ScreenshotFramePainter({
+ required this.opacity,
+ required this.progress,
+ });
+
+ final double opacity;
+ final double progress;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ if (opacity <= 0.0 || size.isEmpty) {
+ return;
+ }
+
+ final horizontalInset = size.width * (0.055 + 0.025 * progress);
+ final verticalInset = size.height * (0.075 + 0.030 * progress);
+ final rect = Rect.fromLTRB(
+ horizontalInset,
+ verticalInset,
+ size.width - horizontalInset,
+ size.height - verticalInset,
+ );
+
+ final cornerLength =
+ (rect.shortestSide * 0.12).clamp(22.0, 54.0).toDouble();
+ final strokeWidth = (1.4 + 0.8 * (1 - progress)).clamp(1.4, 2.2);
+ final paint = Paint()
+ ..color = Colors.white.withValues(alpha: opacity)
+ ..style = PaintingStyle.stroke
+ ..strokeCap = StrokeCap.round
+ ..strokeWidth = strokeWidth;
+
+ final path = Path()
+ ..moveTo(rect.left, rect.top + cornerLength)
+ ..lineTo(rect.left, rect.top)
+ ..lineTo(rect.left + cornerLength, rect.top)
+ ..moveTo(rect.right - cornerLength, rect.top)
+ ..lineTo(rect.right, rect.top)
+ ..lineTo(rect.right, rect.top + cornerLength)
+ ..moveTo(rect.right, rect.bottom - cornerLength)
+ ..lineTo(rect.right, rect.bottom)
+ ..lineTo(rect.right - cornerLength, rect.bottom)
+ ..moveTo(rect.left + cornerLength, rect.bottom)
+ ..lineTo(rect.left, rect.bottom)
+ ..lineTo(rect.left, rect.bottom - cornerLength);
+
+ canvas.drawPath(path, paint);
+ }
+
+ @override
+ bool shouldRepaint(_ScreenshotFramePainter oldDelegate) {
+ return oldDelegate.opacity != opacity || oldDelegate.progress != progress;
+ }
+}
diff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dart
index b9670055..f2a2e7c3 100644
--- a/lib/pages/player/smallest_player_item_panel.dart
+++ b/lib/pages/player/smallest_player_item_panel.dart
@@ -32,7 +32,7 @@ class SmallestPlayerItemPanel extends StatefulWidget {
required this.handleProgressBarDragStart,
required this.handleProgressBarDragEnd,
required this.handleSuperResolutionChange,
- required this.animationController,
+ required this.panelVisibilityController,
required this.keyboardFocus,
required this.acquirePlayerPanelHold,
required this.handleDanmaku,
@@ -54,7 +54,7 @@ class SmallestPlayerItemPanel extends StatefulWidget {
final void Function(ThumbDragDetails details) handleProgressBarDragStart;
final void Function() handleProgressBarDragEnd;
final Future<void> Function(int shaderIndex) handleSuperResolutionChange;
- final AnimationController animationController;
+ final AnimationController panelVisibilityController;
final FocusNode keyboardFocus;
final PlayerPanelHold Function() acquirePlayerPanelHold;
final void Function() showVideoInfo;
@@ -146,21 +146,21 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {
begin: const Offset(0.0, -1.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
bottomOffsetAnimation = Tween<Offset>(
begin: const Offset(0.0, 1.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
leftOffsetAnimation = Tween<Offset>(
begin: const Offset(1.0, 0.0),
end: const Offset(0.0, 0.0),
).animate(CurvedAnimation(
- parent: widget.animationController,
+ parent: widget.panelVisibilityController,
curve: Curves.easeInOut,
));
haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);