From bcf71e559ac3eae3867a11eddfe303e0b8f3f195 Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 24 Feb 2024 12:51:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=82=B9=E8=BF=9B=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E6=88=96=E6=89=8B=E5=8A=A8=E6=92=AD=E6=94=BE=E4=BA=A7=E7=94=9F?= =?UTF-8?q?=E5=85=A8=E5=B1=8F=E6=95=85=E9=9A=9C=E3=80=81=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=A0=8F=E8=B7=B3=E5=8A=A8=EF=BC=9B=E5=A4=9A=E5=B1=82=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/video/detail/view.dart | 155 ++++++++---------- .../video/detail/widgets/header_control.dart | 4 +- lib/plugin/pl_player/controller.dart | 18 +- lib/plugin/pl_player/utils/fullscreen.dart | 4 +- 4 files changed, 76 insertions(+), 105 deletions(-) diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 7f3b65b67..bd2cdcf77 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -23,7 +23,6 @@ import 'package:PiliPalaX/plugin/pl_player/index.dart'; import 'package:PiliPalaX/plugin/pl_player/models/play_repeat.dart'; import 'package:PiliPalaX/services/service_locator.dart'; import 'package:PiliPalaX/utils/storage.dart'; -import 'package:status_bar_control/status_bar_control.dart'; import '../../../services/shutdown_timer_service.dart'; import 'widgets/header_control.dart'; @@ -64,6 +63,7 @@ class _VideoDetailPageState extends State late final AppLifecycleListener _lifecycleListener; bool isShowing = true; RxBool isFullScreen = false.obs; + late StreamSubscription fullScreenStatusListener; @override void initState() { @@ -95,7 +95,6 @@ class _VideoDetailPageState extends State videoSourceInit(); appbarStreamListen(); lifecycleListener(); - fullScreenStatusListener(); autoScreen(); } @@ -105,6 +104,7 @@ class _VideoDetailPageState extends State if (videoDetailController.autoPlay.value) { plPlayerController = videoDetailController.plPlayerController; plPlayerController!.addStatusLister(playerListener); + listenFullScreenStatus(); } } @@ -140,13 +140,13 @@ class _VideoDetailPageState extends State plPlayerController!.play(); } // 播放完展示控制栏 - try { + if (videoDetailController.floating != null) { PiPStatus currentStatus = await videoDetailController.floating!.pipStatus; if (currentStatus == PiPStatus.disabled) { plPlayerController!.onLockControl(false); } - } catch (_) {} + } } } @@ -160,6 +160,7 @@ class _VideoDetailPageState extends State await videoDetailController.playerInit(); plPlayerController = videoDetailController.plPlayerController; plPlayerController!.addStatusLister(playerListener); + listenFullScreenStatus(); videoDetailController.autoPlay.value = true; videoDetailController.isShowCover.value = false; } @@ -185,17 +186,18 @@ class _VideoDetailPageState extends State ); } - void fullScreenStatusListener() { - plPlayerController?.isFullScreen.listen((bool isFullScreen) { - if (isFullScreen) { + void listenFullScreenStatus() { + fullScreenStatusListener = + plPlayerController!.isFullScreen.listen((bool status) { + if (status) { videoDetailController.hiddenReplyReplyPanel(); - enterFullScreen(); + hideStatusBar(); } setState(() { - this.isFullScreen.value = isFullScreen; + isFullScreen.value = status; }); - if (!isFullScreen) { - exitFullScreen(); + if (!status) { + showStatusBar(); if (setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) { autoScreen(); } else { @@ -213,6 +215,7 @@ class _VideoDetailPageState extends State shutdownTimerService.handleWaitingFinished(); if (plPlayerController != null) { plPlayerController!.removeStatusLister(playerListener); + fullScreenStatusListener.cancel(); plPlayerController!.dispose(); } if (videoDetailController.floating != null) { @@ -221,8 +224,7 @@ class _VideoDetailPageState extends State videoPlayerServiceHandler.onVideoDetailDispose(); floating.dispose(); _lifecycleListener.dispose(); - StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); - exitFullScreen(); + showStatusBar(); super.dispose(); } @@ -238,6 +240,7 @@ class _VideoDetailPageState extends State videoDetailController.defaultST = plPlayerController!.position.value; videoIntroController.isPaused = true; plPlayerController!.removeStatusLister(playerListener); + fullScreenStatusListener.cancel(); plPlayerController!.pause(); } setState(() => isShowing = false); @@ -247,10 +250,6 @@ class _VideoDetailPageState extends State @override // 返回当前页面时 void didPopNext() async { - if (plPlayerController != null && - plPlayerController!.videoPlayerController != null) { - setState(() => isShowing = true); - } videoDetailController.isFirstTime = false; final bool autoplay = autoPlayEnable; videoDetailController.playerInit(autoplay: autoplay); @@ -265,6 +264,10 @@ class _VideoDetailPageState extends State plPlayerController?.play(); } plPlayerController?.addStatusLister(playerListener); + if (plPlayerController != null) { + listenFullScreenStatus(); + } + setState(() => isShowing = true); super.didPopNext(); } @@ -288,8 +291,6 @@ class _VideoDetailPageState extends State void autoEnterPip() { final String routePath = Get.currentRoute; - final bool isPortrait = - MediaQuery.of(context).orientation == Orientation.portrait; if (autoPiP && routePath.startsWith('/video')) { floating.enable( @@ -340,7 +341,10 @@ class _VideoDetailPageState extends State : videoheight, width: MediaQuery.of(context).size.width, child: PopScope( - canPop: isFullScreen.value != true, + canPop: isFullScreen.value != true && + (horizontalScreen || + MediaQuery.of(context).orientation == + Orientation.portrait), onPopInvoked: (bool didPop) { if (isFullScreen.value == true) { plPlayerController! @@ -519,34 +523,30 @@ class _VideoDetailPageState extends State child: TabBarView( controller: videoDetailController.tabCtr, children: [ - Builder( - builder: (BuildContext context) { - return CustomScrollView( - key: const PageStorageKey('简介'), - slivers: [ - if (videoDetailController.videoType == - SearchType.video) ...[ - const VideoIntroPanel(), - ] else if (videoDetailController - .videoType == - SearchType.media_bangumi) ...[ - Obx(() => BangumiIntroPanel( - cid: videoDetailController - .cid.value)), - ], - SliverToBoxAdapter( - child: Divider( - indent: 12, - endIndent: 12, - color: Theme.of(context) - .dividerColor - .withOpacity(0.06), - ), - ), - const RelatedVideoPanel(), - ], - ); - }, + CustomScrollView( + key: const PageStorageKey('简介'), + slivers: [ + if (videoDetailController.videoType == + SearchType.video) ...[ + const VideoIntroPanel(), + ] else if (videoDetailController + .videoType == + SearchType.media_bangumi) ...[ + Obx(() => BangumiIntroPanel( + cid: + videoDetailController.cid.value)), + ], + SliverToBoxAdapter( + child: Divider( + indent: 12, + endIndent: 12, + color: Theme.of(context) + .dividerColor + .withOpacity(0.06), + ), + ), + const RelatedVideoPanel(), + ], ), Obx( () => VideoReplyPanel( @@ -799,54 +799,31 @@ class _VideoDetailPageState extends State ); })) ])); - Widget childWhenEnabled = FutureBuilder( - key: Key(heroTag), - future: _futureBuilderFuture, - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.hasData && snapshot.data['status']) { - return Obx( - () => !videoDetailController.autoPlay.value - ? const SizedBox() - : PLVideoPlayer( - controller: plPlayerController!, - headerControl: HeaderControl( - controller: plPlayerController, - videoDetailCtr: videoDetailController, - ), - // danmuWidget: Obx( - // () => PlDanmaku( - // key: Key( - // videoDetailController.danmakuCid.value.toString()), - // cid: videoDetailController.danmakuCid.value, - // playerController: plPlayerController!, - // ), - // ), - ), - ); - } else { - return nil; - } - }, + Widget childWhenEnabled = Obx( + () => !videoDetailController.autoPlay.value + ? const SizedBox() + : PLVideoPlayer( + controller: plPlayerController!, + headerControl: HeaderControl( + controller: plPlayerController, + videoDetailCtr: videoDetailController, + ), + ), ); - // if (!horizontalScreen) { - // if (Platform.isAndroid) { - // return PiPSwitcher( - // childWhenEnabled: childWhenEnabled, - // childWhenDisabled: childWhenDisabled, - // floating: floating,); - // } - // return childWhenDisabled; - // } return OrientationBuilder( builder: (BuildContext context, Orientation orientation) { - print("orientation $orientation"); + if (!isShowing) { + return const SizedBox(); + } if (orientation == Orientation.landscape) { - enterFullScreen(); if (!horizontalScreen) { + hideStatusBar(); videoDetailController.hiddenReplyReplyPanel(); } - } else if (!isFullScreen.value) { - StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); + } else { + if (!isFullScreen.value) { + showStatusBar(); + } } if (Platform.isAndroid) { return PiPSwitcher( diff --git a/lib/pages/video/detail/widgets/header_control.dart b/lib/pages/video/detail/widgets/header_control.dart index cfdcc5a63..5de48ca43 100644 --- a/lib/pages/video/detail/widgets/header_control.dart +++ b/lib/pages/video/detail/widgets/header_control.dart @@ -1078,9 +1078,7 @@ class _HeaderControlState extends State { !setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) { - SystemChrome.setPreferredOrientations([ - DeviceOrientation.portraitUp, - ]) + verticalScreen(), }, Get.back() } diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index ec18f0fc8..f50000018 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -20,7 +20,6 @@ import 'package:PiliPalaX/services/service_locator.dart'; import 'package:PiliPalaX/utils/feed_back.dart'; import 'package:PiliPalaX/utils/storage.dart'; import 'package:screen_brightness/screen_brightness.dart'; -import 'package:status_bar_control/status_bar_control.dart'; import 'package:universal_platform/universal_platform.dart'; // import 'package:wakelock_plus/wakelock_plus.dart'; @@ -943,12 +942,11 @@ class PlPlayerController { // 全屏 Future triggerFullScreen({bool status = true}) async { if (!isFullScreen.value && status) { - await StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE); + // StatusBarControl.setHidden(true, animation: StatusBarAnimation.FADE); + hideStatusBar(); /// 按照视频宽高比决定全屏方向 toggleFullScreen(true); - /// 进入全屏 - await enterFullScreen(); FullScreenMode mode = FullScreenModeCode.fromCode( setting.get(SettingBoxKey.fullScreenMode, defaultValue: 0))!; if (mode == FullScreenMode.vertical || @@ -960,15 +958,13 @@ class PlPlayerController { } else { await landScape(); } - } else if (isFullScreen.value && !status) { - if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) { - StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); - // Get.back(); - // await verticalScreen(); - } - exitFullScreen(); + // StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); + showStatusBar(); toggleFullScreen(false); + if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)){ + await verticalScreen(); + } } } diff --git a/lib/plugin/pl_player/utils/fullscreen.dart b/lib/plugin/pl_player/utils/fullscreen.dart index cafda3279..d58dfde85 100644 --- a/lib/plugin/pl_player/utils/fullscreen.dart +++ b/lib/plugin/pl_player/utils/fullscreen.dart @@ -53,14 +53,14 @@ Future autoScreen() async { ]); } -Future enterFullScreen() async { +Future hideStatusBar() async { await SystemChrome.setEnabledSystemUIMode( SystemUiMode.immersiveSticky, ); } //退出全屏显示 -Future exitFullScreen() async { +Future showStatusBar() async { dynamic document; late SystemUiMode mode = SystemUiMode.edgeToEdge; try {