diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index 143bb90c..350f4230 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -26,6 +26,7 @@ class _PlaySettingState extends State { late dynamic defaultAudioQa; late dynamic defaultDecode; late int defaultFullScreenMode; + late bool lockLandscape; late int defaultBtmProgressBehavior; @override @@ -39,6 +40,8 @@ class _PlaySettingState extends State { defaultValue: VideoDecodeFormats.values.last.code); defaultFullScreenMode = setting.get(SettingBoxKey.fullScreenMode, defaultValue: FullScreenMode.values.first.code); + lockLandscape = setting.get(SettingBoxKey.lockLandscape, + defaultValue: false); defaultBtmProgressBehavior = setting.get(SettingBoxKey.btmProgressBehavior, defaultValue: BtmProgresBehavior.values.first.code); } @@ -133,6 +136,12 @@ class _PlaySettingState extends State { } } ), + const SetSwitchItem( + title: '额外横屏', + subTitle: '执行播放器横屏前,额外施加屏幕旋转方向限制', + setKey: SettingBoxKey.lockLandscape, + defaultVal: false, + ), const SetSwitchItem( title: '开启硬解', subTitle: '以较低功耗播放视频', diff --git a/lib/pages/video/detail/controller.dart b/lib/pages/video/detail/controller.dart index 5d169492..6dbc0ff3 100644 --- a/lib/pages/video/detail/controller.dart +++ b/lib/pages/video/detail/controller.dart @@ -247,10 +247,6 @@ class VideoDetailController extends GetxController plPlayerController.headerControl = headerControl; } - void setTriggerFullScreenCallback(void Function({bool? status}) callback) { - plPlayerController.setTriggerFullscreenCallback(callback); - } - // 视频链接 Future queryVideoUrl() async { var result = await VideoHttp.videoUrl(cid: cid.value, bvid: bvid); diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index c01284d2..70dac19a 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -92,8 +92,6 @@ class _VideoDetailPageState extends State autoPlayEnable = setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true); autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false); - videoDetailController - .setTriggerFullScreenCallback(triggerFullScreenCallback); videoSourceInit(); appbarStreamListen(); lifecycleListener(); @@ -158,8 +156,6 @@ class _VideoDetailPageState extends State /// 未开启自动播放时触发播放 Future handlePlay() async { - videoDetailController - .setTriggerFullScreenCallback(triggerFullScreenCallback); await videoDetailController.playerInit(); plPlayerController = videoDetailController.plPlayerController; plPlayerController!.addStatusLister(playerListener); @@ -193,6 +189,9 @@ class _VideoDetailPageState extends State if (isFullScreen) { videoDetailController.hiddenReplyReplyPanel(); } + setState(() { + this.isFullScreen.value = isFullScreen; + }); }); } @@ -244,8 +243,6 @@ class _VideoDetailPageState extends State } videoDetailController.isFirstTime = false; final bool autoplay = autoPlayEnable; - videoDetailController - .setTriggerFullScreenCallback(triggerFullScreenCallback); videoDetailController.playerInit(autoplay: autoplay); /// 未开启自动播放时,未播放跳转下一页返回/播放后跳转下一页返回 @@ -293,12 +290,6 @@ class _VideoDetailPageState extends State } } - void triggerFullScreenCallback({bool? status}) { - // SmartDialog.showToast('triggerFullScreen $status $isFullScreen.value'); - setState(() { - isFullScreen.value = status ?? !isFullScreen.value; - }); - } @override Widget build(BuildContext context) { diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index c90a223c..ec18f0fc 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -31,7 +31,6 @@ Box localCache = GStrorage.localCache; class PlPlayerController { Player? _videoPlayerController; VideoController? _videoController; - void Function({bool? status})? triggerFullscreenCallback; // 添加一个私有静态变量来保存实例 static PlPlayerController? _instance; @@ -233,11 +232,6 @@ class PlPlayerController { // 播放顺序相关 PlayRepeat playRepeat = PlayRepeat.pause; - void setTriggerFullscreenCallback( - void Function({bool? status}) triggerFullscreenCallback) { - this.triggerFullscreenCallback = triggerFullscreenCallback; - } - void updateSliderPositionSecond() { int newSecond = _sliderPosition.value.inSeconds; if (sliderPositionSeconds.value != newSecond) { @@ -967,9 +961,6 @@ class PlPlayerController { await landScape(); } - if (triggerFullscreenCallback != null) { - triggerFullscreenCallback!(status: status); - } } else if (isFullScreen.value && !status) { if (!setting.get(SettingBoxKey.horizontalScreen, defaultValue: false)) { StatusBarControl.setHidden(false, animation: StatusBarAnimation.FADE); @@ -978,9 +969,6 @@ class PlPlayerController { } exitFullScreen(); toggleFullScreen(false); - if (triggerFullscreenCallback != null) { - triggerFullscreenCallback!(status: status); - } } } diff --git a/lib/plugin/pl_player/utils/fullscreen.dart b/lib/plugin/pl_player/utils/fullscreen.dart index e89a19c6..e2f8c810 100644 --- a/lib/plugin/pl_player/utils/fullscreen.dart +++ b/lib/plugin/pl_player/utils/fullscreen.dart @@ -15,16 +15,14 @@ Future landScape() async { if (kIsWeb) { await document.documentElement?.requestFullscreen(); } else if (Platform.isAndroid || Platform.isIOS) { - // await SystemChrome.setEnabledSystemUIMode( - // SystemUiMode.immersiveSticky, - // overlays: [], - // ); - // await SystemChrome.setPreferredOrientations( - // [ - // DeviceOrientation.landscapeLeft, - // DeviceOrientation.landscapeRight, - // ], - // ); + if (setting.get(SettingBoxKey.lockLandscape, defaultValue: false)) { + await SystemChrome.setPreferredOrientations( + [ + DeviceOrientation.landscapeLeft, + DeviceOrientation.landscapeRight, + ], + ); + } await AutoOrientation.landscapeAutoMode(forceSensor: true); } else if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) { await const MethodChannel('com.alexmercerind/media_kit_video') diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 2cb8ab45..3b10b0ac 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -80,6 +80,7 @@ class SettingBoxKey { defaultAudioQa = 'defaultAudioQa', autoPlayEnable = 'autoPlayEnable', fullScreenMode = 'fullScreenMode', + lockLandscape = 'lockLandscape', defaultDecode = 'defaultDecode', danmakuEnable = 'danmakuEnable', defaultToastOp = 'defaultToastOp',