Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix player orientation (#230)

Predidit9b0c57350a82
diff --git a/lib/pages/video/video_controller.dart b/lib/pages/video/video_controller.dart
index e1d10347..2e50fd5f 100644
--- a/lib/pages/video/video_controller.dart
+++ b/lib/pages/video/video_controller.dart
@@ -71,7 +71,7 @@ abstract class _VideoPageController with Store {
await webviewItemController.loadUrl(urlItem, offset: offset);
}
- Future<void> enterFullScreen() async {
+ Future<void> enterFullScreen({bool lockOrientation = true}) async {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
await windowManager.setFullScreen(true);
return;
@@ -79,6 +79,9 @@ abstract class _VideoPageController with Store {
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.immersiveSticky,
);
+ if (!lockOrientation) {
+ return;
+ }
if (Platform.isAndroid) {
bool isInMultiWindowMode = await Utils.isInMultiWindowMode();
if (isInMultiWindowMode) {
@@ -89,7 +92,7 @@ abstract class _VideoPageController with Store {
}
//退出全屏显示
- Future<void> exitFullScreen() async {
+ Future<void> exitFullScreen({bool lockOrientation = true}) async {
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
await windowManager.setFullScreen(false);
}
@@ -104,7 +107,7 @@ abstract class _VideoPageController with Store {
mode,
overlays: SystemUiOverlay.values,
);
- if (Utils.isCompact()) {
+ if (Utils.isCompact() && lockOrientation) {
if (Platform.isAndroid) {
bool isInMultiWindowMode = await Utils.isInMultiWindowMode();
if (isInMultiWindowMode) {
@@ -140,10 +143,16 @@ abstract class _VideoPageController with Store {
}
}
-//竖屏
+ //竖屏
Future<void> verticalScreen() async {
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
}
+
+ // 解除屏幕旋转限制
+ Future<void> unlockScreenRotation() async {
+ await SystemChrome.setPreferredOrientations([]);
+ }
}
+
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index c8efbf91..3aec4a3b 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -83,66 +83,80 @@ class _VideoPageState extends State<VideoPage>
playerController.mediaPlayer.dispose();
} catch (_) {}
WakelockPlus.disable();
+ videoPageController.unlockScreenRotation();
super.dispose();
}
@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) {});
- return Observer(builder: (context) {
- return Scaffold(
- appBar: ((videoPageController.currentPlugin.useNativePlayer ||
- videoPageController.androidFullscreen)
- ? null
- : SysAppBar(
- title: Text(videoPageController.title),
- )),
- body: SafeArea(
- child: (Utils.isTablet() &&
- MediaQuery.of(context).size.height <
- MediaQuery.of(context).size.width)
- ? Row(
- children: [
- Container(
- color: Colors.black,
- height: MediaQuery.of(context).size.height,
- width: (!videoPageController.androidFullscreen)
- ? MediaQuery.of(context).size.height
- : MediaQuery.of(context).size.width,
- child: playerBody),
- videoPageController.androidFullscreen
- ? Container()
- : Expanded(
- child: Column(
- children: [
- tabBar,
- tabBody,
- ],
- ))
- ],
- )
- : Column(
- children: [
- Container(
- color: Colors.black,
- height: videoPageController.androidFullscreen
- ? MediaQuery.of(context).size.height
- : MediaQuery.of(context).size.width * 9 / 16,
- width: MediaQuery.of(context).size.width,
- child: playerBody),
- videoPageController.androidFullscreen
- ? Container()
- : Expanded(
- child: Column(
- children: [
- tabBar,
- tabBody,
- ],
- ))
- ],
- ),
- ),
- );
+ return OrientationBuilder(builder: (context, orientation) {
+ if (!Utils.isTablet() && !Utils.isDesktop()) {
+ if (orientation == Orientation.landscape &&
+ !videoPageController.androidFullscreen) {
+ videoPageController.enterFullScreen(lockOrientation: false);
+ videoPageController.androidFullscreen = true;
+ } else if (orientation == Orientation.portrait &&
+ videoPageController.androidFullscreen) {
+ videoPageController.exitFullScreen(lockOrientation: false);
+ videoPageController.androidFullscreen = false;
+ }
+ }
+ return Observer(builder: (context) {
+ return Scaffold(
+ appBar: ((videoPageController.currentPlugin.useNativePlayer ||
+ videoPageController.androidFullscreen)
+ ? null
+ : SysAppBar(
+ title: Text(videoPageController.title),
+ )),
+ body: SafeArea(
+ child: (Utils.isTablet() &&
+ MediaQuery.of(context).size.height <
+ MediaQuery.of(context).size.width)
+ ? Row(
+ children: [
+ Container(
+ color: Colors.black,
+ height: MediaQuery.of(context).size.height,
+ width: (!videoPageController.androidFullscreen)
+ ? MediaQuery.of(context).size.height
+ : MediaQuery.of(context).size.width,
+ child: playerBody),
+ videoPageController.androidFullscreen
+ ? Container()
+ : Expanded(
+ child: Column(
+ children: [
+ tabBar,
+ tabBody,
+ ],
+ ))
+ ],
+ )
+ : Column(
+ children: [
+ Container(
+ color: Colors.black,
+ height: videoPageController.androidFullscreen
+ ? MediaQuery.of(context).size.height
+ : MediaQuery.of(context).size.width * 9 / 16,
+ width: MediaQuery.of(context).size.width,
+ child: playerBody),
+ videoPageController.androidFullscreen
+ ? Container()
+ : Expanded(
+ child: Column(
+ children: [
+ tabBar,
+ tabBody,
+ ],
+ ))
+ ],
+ ),
+ ),
+ );
+ });
});
}
@@ -172,7 +186,9 @@ class _VideoPageState extends State<VideoPage>
itemCount: videoPageController.logLines.length,
itemBuilder: (context, index) {
return Text(
- videoPageController.logLines.isEmpty ? '' : videoPageController.logLines[index],
+ videoPageController.logLines.isEmpty
+ ? ''
+ : videoPageController.logLines[index],
style: const TextStyle(
color: Colors.white,
),
@@ -215,12 +231,11 @@ class _VideoPageState extends State<VideoPage>
/// The webview_windows component cannot be removed from the widget tree; otherwise, it can never be reinitialized.
Positioned(
child: SizedBox(
- height: (videoPageController.loading ||
- videoPageController.currentPlugin.useNativePlayer)
- ? 0
- : null,
- child: const WebviewItem()
- ))
+ height: (videoPageController.loading ||
+ videoPageController.currentPlugin.useNativePlayer)
+ ? 0
+ : null,
+ child: const WebviewItem()))
],
);
}