opt fullscreen

Closes #1442

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-10-03 21:14:33 +08:00
parent 5747dee03d
commit 16c152d306
3 changed files with 90 additions and 87 deletions

View File

@@ -369,7 +369,9 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
}
PageUtils.routeObserver.unsubscribe(this);
WidgetsBinding.instance.removeObserver(this);
showStatusBar();
if (Utils.isMobile) {
showStatusBar();
}
super.dispose();
}
@@ -545,7 +547,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
videoDetailController.animationController
..removeListener(animListener)
..addListener(animListener);
if (mounted && isShowing && !isFullScreen) {
if (Utils.isMobile && mounted && isShowing && !isFullScreen) {
if (isPortrait) {
if (!videoDetailController.imageStatus) {
showStatusBar();

View File

@@ -1511,48 +1511,53 @@ class PlPlayerController {
bool status = true,
bool inAppFullScreen = false,
}) async {
if (isFullScreen.value == status) return;
if (fsProcessing) {
return;
}
fsProcessing = true;
if (!isFullScreen.value && status) {
hideStatusBar();
toggleFullScreen(status);
/// 按照视频宽高比决定全屏方向
toggleFullScreen(true);
/// 进入全屏
if (mode == FullScreenMode.none) {
fsProcessing = false;
return;
}
if (mode == FullScreenMode.gravity) {
fullAutoModeForceSensor();
fsProcessing = false;
return;
}
late final size = Get.size;
if (Utils.isMobile &&
(mode == FullScreenMode.vertical ||
(mode == FullScreenMode.auto && isVertical) ||
(mode == FullScreenMode.ratio &&
(isVertical || size.height / size.width < 1.25)))) {
await verticalScreenForTwoSeconds();
if (status) {
if (Utils.isMobile) {
hideStatusBar();
if (mode == FullScreenMode.none) {
fsProcessing = false;
return;
}
if (mode == FullScreenMode.gravity) {
await fullAutoModeForceSensor();
fsProcessing = false;
return;
}
late final size = Get.mediaQuery.size;
if ((mode == FullScreenMode.vertical ||
(mode == FullScreenMode.auto && isVertical) ||
(mode == FullScreenMode.ratio &&
(isVertical || size.height / size.width < 1.25)))) {
await verticalScreenForTwoSeconds();
} else {
await landscape();
}
} else {
await landscape(inAppFullScreen: inAppFullScreen);
await enterDesktopFullscreen();
}
} else if (isFullScreen.value && !status) {
showStatusBar();
toggleFullScreen(false);
if (mode == FullScreenMode.none) {
fsProcessing = false;
return;
}
if (!horizontalScreen) {
await verticalScreenForTwoSeconds();
} else {
if (Utils.isMobile) {
showStatusBar();
if (mode == FullScreenMode.none) {
fsProcessing = false;
return;
}
if (!horizontalScreen) {
await verticalScreenForTwoSeconds();
} else {
await autoScreen();
}
} else {
await autoScreen();
await exitDesktopFullscreen();
}
}
fsProcessing = false;

View File

@@ -7,93 +7,89 @@ import 'package:auto_orientation/auto_orientation.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
//横屏
Future<void> landscape({bool inAppFullScreen = false}) async {
try {
if (Utils.isMobile) {
await AutoOrientation.landscapeAutoMode(forceSensor: true);
} else if (Utils.isDesktop && !inAppFullScreen) {
bool _isDesktopFullScreen = false;
Future<void> enterDesktopFullscreen({bool inAppFullScreen = false}) async {
if (!inAppFullScreen && !_isDesktopFullScreen) {
_isDesktopFullScreen = true;
try {
await const MethodChannel(
'com.alexmercerind/media_kit_video',
).invokeMethod('Utils.EnterNativeFullscreen');
} catch (_) {
if (kDebugMode) rethrow;
}
} catch (exception, stacktrace) {
if (kDebugMode) {
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
}
Future<void> exitDesktopFullscreen() async {
if (_isDesktopFullScreen) {
_isDesktopFullScreen = false;
try {
await const MethodChannel(
'com.alexmercerind/media_kit_video',
).invokeMethod('Utils.ExitNativeFullscreen');
} catch (_) {
if (kDebugMode) rethrow;
}
}
}
//横屏
Future<void> landscape() async {
try {
await AutoOrientation.landscapeAutoMode(forceSensor: true);
} catch (_) {
if (kDebugMode) rethrow;
}
}
//竖屏
Future<void> verticalScreenForTwoSeconds() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
await autoScreen();
}
//竖屏
Future<void> verticalScreen() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
}
//全向
bool allowRotateScreen = Pref.allowRotateScreen;
Future<void> autoScreen() async {
if (!allowRotateScreen) {
return;
if (Utils.isMobile && allowRotateScreen) {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
Future<void> fullAutoModeForceSensor() async {
await AutoOrientation.fullAutoMode(forceSensor: true);
}
bool _showStatusBar = true;
Future<void> hideStatusBar() async {
if (!_showStatusBar) {
return;
}
_showStatusBar = false;
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
);
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
}
bool _showStatusBar = true;
//退出全屏显示
Future<void> showStatusBar() async {
if (_showStatusBar) {
return;
}
_showStatusBar = true;
try {
if (Utils.isMobile) {
SystemUiMode mode;
if (Platform.isAndroid && (await Utils.sdkInt < 29)) {
mode = SystemUiMode.manual;
} else {
mode = SystemUiMode.edgeToEdge;
}
await SystemChrome.setEnabledSystemUIMode(
mode,
overlays: SystemUiOverlay.values,
);
} else if (Utils.isDesktop) {
await const MethodChannel(
'com.alexmercerind/media_kit_video',
).invokeMethod('Utils.ExitNativeFullscreen');
}
} catch (_) {
if (kDebugMode) rethrow;
SystemUiMode mode;
if (Platform.isAndroid && (await Utils.sdkInt < 29)) {
mode = SystemUiMode.manual;
} else {
mode = SystemUiMode.edgeToEdge;
}
await SystemChrome.setEnabledSystemUIMode(
mode,
overlays: SystemUiOverlay.values,
);
}