improve player gesture

Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-05-14 10:56:37 +08:00
parent 2f12e1a1c0
commit 025775d231
2 changed files with 61 additions and 14 deletions

View File

@@ -0,0 +1,43 @@
import 'package:flutter/gestures.dart'
show
GestureRecognizer,
RecognizerCallback,
ScaleGestureRecognizer,
LongPressGestureRecognizer;
mixin PlayerGestureMixin on GestureRecognizer {
bool isPosAllowed = true;
@override
T? invokeCallback<T>(
String name,
RecognizerCallback<T> callback, {
String Function()? debugReport,
}) {
if (!isPosAllowed) return null;
return super.invokeCallback(name, callback, debugReport: debugReport);
}
}
class PlayerScaleGestureRecognizer extends ScaleGestureRecognizer
with PlayerGestureMixin {
PlayerScaleGestureRecognizer({
super.debugOwner,
super.supportedDevices,
super.allowedButtonsFilter,
super.dragStartBehavior,
super.trackpadScrollCausesScale,
super.trackpadScrollToScaleFactor,
});
}
class PlayerLongPressGestureRecognizer extends LongPressGestureRecognizer
with PlayerGestureMixin {
PlayerLongPressGestureRecognizer({
Duration? duration,
super.postAcceptSlopTolerance,
super.supportedDevices,
super.debugOwner,
super.allowedButtonsFilter,
});
}

View File

@@ -10,6 +10,7 @@ import 'package:PiliPlus/common/widgets/cropped_image.dart';
import 'package:PiliPlus/common/widgets/custom_icon.dart'; import 'package:PiliPlus/common/widgets/custom_icon.dart';
import 'package:PiliPlus/common/widgets/disabled_icon.dart'; import 'package:PiliPlus/common/widgets/disabled_icon.dart';
import 'package:PiliPlus/common/widgets/gesture/mouse_interactive_viewer.dart'; import 'package:PiliPlus/common/widgets/gesture/mouse_interactive_viewer.dart';
import 'package:PiliPlus/common/widgets/gesture/player_gesture_recognizer.dart';
import 'package:PiliPlus/common/widgets/pair.dart'; import 'package:PiliPlus/common/widgets/pair.dart';
import 'package:PiliPlus/common/widgets/player_bar.dart'; import 'package:PiliPlus/common/widgets/player_bar.dart';
import 'package:PiliPlus/common/widgets/progress_bar/audio_video_progress_bar.dart'; import 'package:PiliPlus/common/widgets/progress_bar/audio_video_progress_bar.dart';
@@ -242,7 +243,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_doubleTapGestureRecognizer = DoubleTapGestureRecognizer() _doubleTapGestureRecognizer = DoubleTapGestureRecognizer()
..onDoubleTapDown = _onDoubleTapDown; ..onDoubleTapDown = _onDoubleTapDown;
_scaleGestureRecognizer = ScaleGestureRecognizer( _scaleGestureRecognizer = PlayerScaleGestureRecognizer(
debugOwner: this, debugOwner: this,
dragStartBehavior: .start, dragStartBehavior: .start,
allowedButtonsFilter: (buttons) => buttons == kPrimaryButton, allowedButtonsFilter: (buttons) => buttons == kPrimaryButton,
@@ -1007,9 +1008,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
} }
LongPressGestureRecognizer? _longPressRecognizer; PlayerLongPressGestureRecognizer? _longPressRecognizer;
LongPressGestureRecognizer get longPressRecognizer => PlayerLongPressGestureRecognizer get longPressRecognizer =>
_longPressRecognizer ??= LongPressGestureRecognizer() _longPressRecognizer ??= PlayerLongPressGestureRecognizer()
..onLongPressStart = ((_) => ..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true)) plPlayerController.setLongPressStatus(true))
..onLongPressEnd = ((_) => plPlayerController.setLongPressStatus(false)) ..onLongPressEnd = ((_) => plPlayerController.setLongPressStatus(false))
@@ -1017,9 +1018,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
plPlayerController.setLongPressStatus(false)); plPlayerController.setLongPressStatus(false));
late final TapGestureRecognizer _tapGestureRecognizer; late final TapGestureRecognizer _tapGestureRecognizer;
late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer; late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer;
late final ScaleGestureRecognizer _scaleGestureRecognizer; late final PlayerScaleGestureRecognizer _scaleGestureRecognizer;
static const _kOffsetThreshold = 30.0; static const _kOffsetThreshold = 25.0;
bool _isPositionAllowed(Offset offset) { bool _isPositionAllowed(Offset offset) {
if (offset.dx < _kOffsetThreshold || if (offset.dx < _kOffsetThreshold ||
offset.dy < _kOffsetThreshold || offset.dy < _kOffsetThreshold ||
@@ -1051,15 +1052,18 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final controlsUnlock = !plPlayerController.controlsLock.value; final controlsUnlock = !plPlayerController.controlsLock.value;
if (PlatformUtils.isMobile) { if (PlatformUtils.isMobile) {
if (_isPositionAllowed(event.localPosition)) { _tapGestureRecognizer.addPointer(event);
_tapGestureRecognizer.addPointer(event); if (controlsUnlock) {
if (controlsUnlock) { final isPosAllowed = _isPositionAllowed(event.localPosition);
if (!plPlayerController.isLive) { if (!plPlayerController.isLive) {
_doubleTapGestureRecognizer.addPointer(event); _doubleTapGestureRecognizer.addPointer(event);
longPressRecognizer.addPointer(event); longPressRecognizer
} ..isPosAllowed = isPosAllowed
_scaleGestureRecognizer.addPointer(event); ..addPointer(event);
} }
_scaleGestureRecognizer
..isPosAllowed = isPosAllowed
..addPointer(event);
} }
} else if (controlsUnlock) { } else if (controlsUnlock) {
if (plPlayerController.isLive) { if (plPlayerController.isLive) {