opt player gesture

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-10-13 12:52:15 +08:00
parent 23d235b8f4
commit ed8c39aa76

View File

@@ -172,7 +172,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
); );
videoController = plPlayerController.videoController!; videoController = plPlayerController.videoController!;
if (Utils.isMobile) { if (isMobile) {
Future.microtask(() async { Future.microtask(() async {
try { try {
FlutterVolumeController.updateShowSystemUI(true); FlutterVolumeController.updateShowSystemUI(true);
@@ -212,6 +212,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} catch (_) {} } catch (_) {}
}); });
} }
_tapGestureRecognizer = TapGestureRecognizer()..onTapUp = onTapUp;
_doubleTapGestureRecognizer = DoubleTapGestureRecognizer()
..onDoubleTapDown = onDoubleTapDown;
} }
Future<void> setBrightness(double value) async { Future<void> setBrightness(double value) async {
@@ -238,7 +242,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
_listener?.cancel(); _listener?.cancel();
_controlsListener?.cancel(); _controlsListener?.cancel();
animationController.dispose(); animationController.dispose();
if (Utils.isMobile) { if (isMobile) {
FlutterVolumeController.removeListener(); FlutterVolumeController.removeListener();
} }
transformationController.dispose(); transformationController.dispose();
@@ -430,7 +434,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
videoDetailController.showVP.value = videoDetailController.showVP.value =
!videoDetailController.showVP.value; !videoDetailController.showVP.value;
}, },
onSecondaryTap: Utils.isMobile onSecondaryTap: isMobile
? null ? null
: () => videoDetailController.showVP.value = : () => videoDetailController.showVP.value =
!videoDetailController.showVP.value, !videoDetailController.showVP.value,
@@ -869,8 +873,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final double tapPosition = details.localFocalPoint.dx; final double tapPosition = details.localFocalPoint.dx;
final double sectionWidth = maxWidth / 3; final double sectionWidth = maxWidth / 3;
if (tapPosition < sectionWidth) { if (tapPosition < sectionWidth) {
if (Utils.isDesktop || if (!isMobile || !plPlayerController.enableSlideVolumeBrightness) {
!plPlayerController.enableSlideVolumeBrightness) {
return; return;
} }
// 左边区域 // 左边区域
@@ -1073,7 +1076,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
onTapDesktop(); onTapDesktop();
break; break;
default: default:
if (kDebugMode && Utils.isMobile) { if (kDebugMode && isMobile) {
final ctr = plPlayerController.danmakuController; final ctr = plPlayerController.danmakuController;
if (ctr != null) { if (ctr != null) {
final item = ctr.findSingleDanmaku(details.localPosition); final item = ctr.findSingleDanmaku(details.localPosition);
@@ -1095,7 +1098,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
void onDoubleTapDown(TapDownDetails details) { void onDoubleTapDown(TapDownDetails details) {
switch (details.kind) { switch (details.kind) {
case ui.PointerDeviceKind.mouse when Utils.isDesktop: case ui.PointerDeviceKind.mouse when !isMobile:
onDoubleTapDesktop(); onDoubleTapDesktop();
break; break;
default: default:
@@ -1104,12 +1107,19 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
} }
final isMobile = Utils.isMobile;
LongPressGestureRecognizer? _longPressRecognizer; LongPressGestureRecognizer? _longPressRecognizer;
final _tapGestureRecognizer = TapGestureRecognizer(); LongPressGestureRecognizer get longPressRecognizer =>
final _doubleTapGestureRecognizer = DoubleTapGestureRecognizer(); (_longPressRecognizer ??= LongPressGestureRecognizer())
..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true))
..onLongPressEnd = ((_) =>
plPlayerController.setLongPressStatus(false));
late final TapGestureRecognizer _tapGestureRecognizer;
late final DoubleTapGestureRecognizer _doubleTapGestureRecognizer;
void onPointerDown(PointerDownEvent event) { void onPointerDown(PointerDownEvent event) {
if (Utils.isDesktop) { if (!isMobile) {
final buttons = event.buttons; final buttons = event.buttons;
final isSecondaryBtn = buttons == kSecondaryMouseButton; final isSecondaryBtn = buttons == kSecondaryMouseButton;
if (isSecondaryBtn || buttons == kMiddleMouseButton) { if (isSecondaryBtn || buttons == kMiddleMouseButton) {
@@ -1126,18 +1136,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
if (!plPlayerController.isLive) { if (!plPlayerController.isLive) {
(_longPressRecognizer ??= LongPressGestureRecognizer()) longPressRecognizer.addPointer(event);
..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true))
..onLongPressEnd = ((_) => plPlayerController.setLongPressStatus(false))
..addPointer(event);
} }
_tapGestureRecognizer _tapGestureRecognizer.addPointer(event);
..onTapUp = onTapUp _doubleTapGestureRecognizer.addPointer(event);
..addPointer(event);
_doubleTapGestureRecognizer
..onDoubleTapDown = onDoubleTapDown
..addPointer(event);
} }
void _showControlsIfNeeded() { void _showControlsIfNeeded() {
@@ -1246,9 +1248,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final gestureWidget = Listener( final gestureWidget = Listener(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onPointerDown: onPointerDown, onPointerDown: onPointerDown,
onPointerPanZoomUpdate: onPointerPanZoomUpdate, onPointerPanZoomUpdate: isMobile ? null : onPointerPanZoomUpdate,
onPointerPanZoomEnd: onPointerPanZoomEnd, onPointerPanZoomEnd: isMobile ? null : onPointerPanZoomEnd,
onPointerSignal: onPointerSignal, onPointerSignal: isMobile ? null : onPointerSignal,
); );
final child = Stack( final child = Stack(
@@ -1277,10 +1279,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
aspectRatio: videoFit.aspectRatio, aspectRatio: videoFit.aspectRatio,
dmWidget: widget.danmuWidget, dmWidget: widget.danmuWidget,
transformationController: transformationController, transformationController: transformationController,
scaleEnabled: scaleEnabled: isMobile && !plPlayerController.controlsLock.value,
!Utils.isDesktop && !plPlayerController.controlsLock.value,
enableShrinkVideoSize: enableShrinkVideoSize:
!Utils.isDesktop && plPlayerController.enableShrinkVideoSize, isMobile && plPlayerController.enableShrinkVideoSize,
onInteractionStart: _onInteractionStart, // TODO: refa gesture onInteractionStart: _onInteractionStart, // TODO: refa gesture
onInteractionUpdate: _onInteractionUpdate, onInteractionUpdate: _onInteractionUpdate,
onInteractionEnd: _onInteractionEnd, onInteractionEnd: _onInteractionEnd,
@@ -1707,7 +1708,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
), ),
), ),
), ),
if (Utils.isMobile) if (isMobile)
buildViewPointWidget( buildViewPointWidget(
videoDetailController, videoDetailController,
plPlayerController, plPlayerController,
@@ -2022,7 +2023,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}), }),
], ],
); );
if (!Utils.isMobile) { if (!isMobile) {
return Obx( return Obx(
() => MouseRegion( () => MouseRegion(
cursor: !plPlayerController.showControls.value && isFullScreen cursor: !plPlayerController.showControls.value && isFullScreen