opt player gesture

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-10-13 12:39:22 +08:00
parent 8bea09b78a
commit 23d235b8f4
2 changed files with 60 additions and 42 deletions

View File

@@ -232,6 +232,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
@override @override
void dispose() { void dispose() {
_tapGestureRecognizer.dispose();
_longPressRecognizer?.dispose();
_doubleTapGestureRecognizer.dispose();
_listener?.cancel(); _listener?.cancel();
_controlsListener?.cancel(); _controlsListener?.cancel();
animationController.dispose(); animationController.dispose();
@@ -1064,8 +1067,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
plPlayerController.triggerFullScreen(status: !isFullScreen); plPlayerController.triggerFullScreen(status: !isFullScreen);
} }
void onTapUp(TapUpDetails event) { void onTapUp(TapUpDetails details) {
switch (event.kind) { switch (details.kind) {
case ui.PointerDeviceKind.mouse when (Utils.isDesktop): case ui.PointerDeviceKind.mouse when (Utils.isDesktop):
onTapDesktop(); onTapDesktop();
break; break;
@@ -1073,14 +1076,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
if (kDebugMode && Utils.isMobile) { if (kDebugMode && Utils.isMobile) {
final ctr = plPlayerController.danmakuController; final ctr = plPlayerController.danmakuController;
if (ctr != null) { if (ctr != null) {
final item = ctr.findSingleDanmaku(event.localPosition); final item = ctr.findSingleDanmaku(details.localPosition);
if (item == null) { if (item == null) {
if (_suspendedDm.value != null) { if (_suspendedDm.value != null) {
_removeOverlay(); _removeOverlay();
break; break;
} }
} else if (item != _suspendedDm.value?.item) { } else if (item != _suspendedDm.value?.item) {
_showOverlay(item, event, ctr); _showOverlay(item, details, ctr);
break; break;
} }
} }
@@ -1101,7 +1104,12 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
} }
} }
LongPressGestureRecognizer? _longPressRecognizer;
final _tapGestureRecognizer = TapGestureRecognizer();
final _doubleTapGestureRecognizer = DoubleTapGestureRecognizer();
void onPointerDown(PointerDownEvent event) { void onPointerDown(PointerDownEvent event) {
if (Utils.isDesktop) {
final buttons = event.buttons; final buttons = event.buttons;
final isSecondaryBtn = buttons == kSecondaryMouseButton; final isSecondaryBtn = buttons == kSecondaryMouseButton;
if (isSecondaryBtn || buttons == kMiddleMouseButton) { if (isSecondaryBtn || buttons == kMiddleMouseButton) {
@@ -1113,9 +1121,25 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
.whenComplete( .whenComplete(
() => plPlayerController.initialFocalPoint = Offset.zero, () => plPlayerController.initialFocalPoint = Offset.zero,
); );
return;
} }
} }
if (!plPlayerController.isLive) {
(_longPressRecognizer ??= LongPressGestureRecognizer())
..onLongPressStart = ((_) =>
plPlayerController.setLongPressStatus(true))
..onLongPressEnd = ((_) => plPlayerController.setLongPressStatus(false))
..addPointer(event);
}
_tapGestureRecognizer
..onTapUp = onTapUp
..addPointer(event);
_doubleTapGestureRecognizer
..onDoubleTapDown = onDoubleTapDown
..addPointer(event);
}
void _showControlsIfNeeded() { void _showControlsIfNeeded() {
if (plPlayerController.isLive) return; if (plPlayerController.isLive) return;
late final isFullScreen = this.isFullScreen; late final isFullScreen = this.isFullScreen;
@@ -1219,6 +1243,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
final isFullScreen = this.isFullScreen; final isFullScreen = this.isFullScreen;
final isLive = plPlayerController.isLive; final isLive = plPlayerController.isLive;
final gestureWidget = Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: onPointerDown,
onPointerPanZoomUpdate: onPointerPanZoomUpdate,
onPointerPanZoomEnd: onPointerPanZoomEnd,
onPointerSignal: onPointerSignal,
);
final child = Stack( final child = Stack(
fit: StackFit.passthrough, fit: StackFit.passthrough,
key: _playerKey, key: _playerKey,
@@ -1254,14 +1286,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
onInteractionEnd: _onInteractionEnd, onInteractionEnd: _onInteractionEnd,
flipX: plPlayerController.flipX.value, flipX: plPlayerController.flipX.value,
flipY: plPlayerController.flipY.value, flipY: plPlayerController.flipY.value,
onTapUp: onTapUp, gestureWidget: gestureWidget,
onDoubleTapDown: onDoubleTapDown,
onLongPressStart: isLive
? null
: (_) => plPlayerController.setLongPressStatus(true),
onLongPressEnd: isLive
? null
: (_) => plPlayerController.setLongPressStatus(false),
enableDragSubtitle: plPlayerController.enableDragSubtitle, enableDragSubtitle: plPlayerController.enableDragSubtitle,
onUpdatePadding: plPlayerController.onUpdatePadding, onUpdatePadding: plPlayerController.onUpdatePadding,
); );
@@ -1998,13 +2023,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
], ],
); );
if (!Utils.isMobile) { if (!Utils.isMobile) {
return Listener( return Obx(
behavior: HitTestBehavior.translucent,
onPointerDown: onPointerDown,
onPointerPanZoomUpdate: onPointerPanZoomUpdate,
onPointerPanZoomEnd: onPointerPanZoomEnd,
onPointerSignal: onPointerSignal,
child: Obx(
() => MouseRegion( () => MouseRegion(
cursor: !plPlayerController.showControls.value && isFullScreen cursor: !plPlayerController.showControls.value && isFullScreen
? SystemMouseCursors.none ? SystemMouseCursors.none
@@ -2015,7 +2034,6 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
widget.videoDetailController?.showSteinEdgeInfo.value ?? false, widget.videoDetailController?.showSteinEdgeInfo.value ?? false,
child: child, child: child,
), ),
),
); );
} }
return child; return child;
@@ -2194,7 +2212,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
void _showOverlay( void _showOverlay(
DanmakuItem<DanmakuExtra> item, DanmakuItem<DanmakuExtra> item,
PositionedGestureDetails event, TapUpDetails event,
DanmakuController<DanmakuExtra> ctr, DanmakuController<DanmakuExtra> ctr,
) { ) {
_removeOverlay(); _removeOverlay();

View File

@@ -1166,7 +1166,7 @@ packages:
description: description:
path: media_kit_video path: media_kit_video
ref: "version_1.2.5" ref: "version_1.2.5"
resolved-ref: "2755671b0263378d216bf2b3fe9bada796e702e9" resolved-ref: "8f15c273f3e5c05476d8b19881719a1bd906c4f2"
url: "https://github.com/bggRGjQaUbCoE/media-kit.git" url: "https://github.com/bggRGjQaUbCoE/media-kit.git"
source: git source: git
version: "1.2.5" version: "1.2.5"