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