diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 26e5356f3..46b1d83b8 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -49,7 +49,7 @@ import 'package:easy_debounce/easy_throttle.dart'; import 'package:floating/floating.dart'; import 'package:flutter/foundation.dart' show kDebugMode; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart' show HapticFeedback; +import 'package:flutter/services.dart' show HapticFeedback, DeviceOrientation; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_volume_controller/flutter_volume_controller.dart'; import 'package:get/get.dart'; @@ -516,32 +516,41 @@ class PlPlayerController with BlockConfigMixin { bool visible = true; - StreamSubscription? _orientationListener; + DeviceOrientation? _orientation; + late final checkIsAutoRotate = Platform.isAndroid && mode != .gravity; + StreamSubscription? _orientationListener; void _stopOrientationListener() { _orientationListener?.cancel(); _orientationListener = null; } - void _onOrientationChanged(NativeDeviceOrientation value) { + void _onOrientationChanged(OrientationParams param) { if (!visible) return; - switch (value) { + final orientation = _orientation = param.orientation; + final isFullScreen = this.isFullScreen.value; + if (checkIsAutoRotate && + param.isAutoRotate != true && + (!isFullScreen || _isVertical || orientation == .portraitUp)) { + return; + } + switch (orientation) { case .portraitUp: if (!_isVertical && controlsLock.value) return; - if (!horizontalScreen && !_isVertical && isFullScreen.value) { - triggerFullScreen(status: false, orientation: value); + if (!horizontalScreen && !_isVertical && isFullScreen) { + triggerFullScreen(status: false, orientation: orientation); } else { portraitUpMode(); } case .landscapeLeft: - if (!horizontalScreen && !isFullScreen.value) { - triggerFullScreen(orientation: value); + if (!horizontalScreen && !isFullScreen) { + triggerFullScreen(orientation: orientation); } else { landscapeLeftMode(); } case .landscapeRight: - if (!horizontalScreen && !isFullScreen.value) { - triggerFullScreen(orientation: value); + if (!horizontalScreen && !isFullScreen) { + triggerFullScreen(orientation: orientation); } else { landscapeRightMode(); } @@ -551,11 +560,11 @@ class PlPlayerController with BlockConfigMixin { // 添加一个私有构造函数 PlPlayerController._() { - if (PlatformUtils.isMobile) { + if (PlatformUtils.isMobile && !horizontalScreen) { _orientationListener = NativeDeviceOrientationPlatform.instance .onOrientationChanged( useSensor: Platform.isAndroid, - checkIsAutoRotate: mode != .gravity, + checkIsAutoRotate: checkIsAutoRotate, ) .listen(_onOrientationChanged); } @@ -1412,7 +1421,7 @@ class PlPlayerController with BlockConfigMixin { Future triggerFullScreen({ bool status = true, bool inAppFullScreen = false, - NativeDeviceOrientation? orientation, + DeviceOrientation? orientation, }) async { if (isDesktopPip) return; if (isFullScreen.value == status) return; @@ -1424,6 +1433,7 @@ class PlPlayerController with BlockConfigMixin { if (status) { if (PlatformUtils.isMobile) { hideStatusBar(); + if (horizontalScreen) return; if (orientation == null && mode == .none) { return; } @@ -1437,7 +1447,7 @@ class PlPlayerController with BlockConfigMixin { // https://github.com/flutter/flutter/issues/73651 // https://github.com/flutter/flutter/issues/183708 if (Platform.isAndroid) { - if (orientation == .landscapeRight) { + if ((orientation ?? _orientation) == .landscapeRight) { await landscapeRightMode(); } else { await landscapeLeftMode(); @@ -1569,9 +1579,7 @@ class PlPlayerController with BlockConfigMixin { bool get isCloseAll => _isCloseAll; void resetScreenRotation() { - if (horizontalScreen) { - fullMode(); - } else { + if (!horizontalScreen) { portraitUpMode(); } } diff --git a/lib/plugin/pl_player/utils/fullscreen.dart b/lib/plugin/pl_player/utils/fullscreen.dart index 137bcba8b..3c7065f2f 100644 --- a/lib/plugin/pl_player/utils/fullscreen.dart +++ b/lib/plugin/pl_player/utils/fullscreen.dart @@ -44,6 +44,10 @@ Future? portraitUpMode() { return _setPreferredOrientations(const [.portraitUp]); } +Future? portraitDownMode() { + return _setPreferredOrientations(const [.portraitDown]); +} + Future? landscapeLeftMode() { return _setPreferredOrientations(const [.landscapeLeft]); } @@ -54,7 +58,7 @@ Future? landscapeRightMode() { Future? fullMode() { return _setPreferredOrientations( - const [.portraitUp, .landscapeLeft, .landscapeRight], + const [.portraitUp, .portraitDown, .landscapeLeft, .landscapeRight], ); } diff --git a/pubspec.lock b/pubspec.lock index e0aadb4a8..15c008449 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1235,7 +1235,7 @@ packages: description: path: "." ref: master - resolved-ref: "42454199133e83a9a31f0fb0107d14af1f96f959" + resolved-ref: "64cbc7886f5a5a5ecb09a34aab0d8b9ee48d03d2" url: "https://github.com/bggRGjQaUbCoE/flutter_native_device_orientation.git" source: git version: "2.0.5"