From 81bf8d915cac2e48b6b0c1a94068a89d90bc42cc Mon Sep 17 00:00:00 2001 From: guozhigq Date: Mon, 23 Oct 2023 23:34:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E8=87=B3=E5=90=8E=E5=8F=B0=E8=87=AA=E5=8A=A8=E7=94=BB=E4=B8=AD?= =?UTF-8?q?=E7=94=BB=20issues=20#212?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/setting/play_setting.dart | 6 ++++++ lib/pages/video/detail/view.dart | 21 ++++++++++++++++++++- lib/utils/storage.dart | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/pages/setting/play_setting.dart b/lib/pages/setting/play_setting.dart index 6606f3c4..82459be9 100644 --- a/lib/pages/setting/play_setting.dart +++ b/lib/pages/setting/play_setting.dart @@ -85,6 +85,12 @@ class _PlaySettingState extends State { setKey: SettingBoxKey.enableBackgroundPlay, defaultVal: false, ), + const SetSwitchItem( + title: '自动PiP播放', + subTitle: 'app切换至后台时画中画播放', + setKey: SettingBoxKey.autoPiP, + defaultVal: false, + ), const SetSwitchItem( title: '自动全屏', subTitle: '视频开始播放时进入全屏', diff --git a/lib/pages/video/detail/view.dart b/lib/pages/video/detail/view.dart index 0debd259..75d91c23 100644 --- a/lib/pages/video/detail/view.dart +++ b/lib/pages/video/detail/view.dart @@ -32,7 +32,7 @@ class VideoDetailPage extends StatefulWidget { } class _VideoDetailPageState extends State - with TickerProviderStateMixin, RouteAware { + with TickerProviderStateMixin, RouteAware, WidgetsBindingObserver { late VideoDetailController videoDetailController; PlPlayerController? plPlayerController; final ScrollController _extendNestCtr = ScrollController(); @@ -52,6 +52,8 @@ class _VideoDetailPageState extends State // 自动退出全屏 late bool autoExitFullcreen; late bool autoPlayEnable; + late bool autoPiP; + final floating = Floating(); @override void initState() { @@ -65,8 +67,11 @@ class _VideoDetailPageState extends State setting.get(SettingBoxKey.enableAutoExit, defaultValue: false); autoPlayEnable = setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true); + autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false); + videoSourceInit(); appbarStreamListen(); + WidgetsBinding.instance.addObserver(this); } // 获取视频资源,初始化播放器 @@ -149,6 +154,8 @@ class _VideoDetailPageState extends State if (videoDetailController.floating != null) { videoDetailController.floating!.dispose(); } + WidgetsBinding.instance.removeObserver(this); + floating.dispose(); super.dispose(); } @@ -195,6 +202,17 @@ class _VideoDetailPageState extends State .subscribe(this, ModalRoute.of(context) as PageRoute); } + @override + void didChangeAppLifecycleState(AppLifecycleState lifecycleState) { + if (lifecycleState == AppLifecycleState.inactive && autoPiP) { + floating.enable( + aspectRatio: Rational( + videoDetailController.data.dash!.video!.first.width!, + videoDetailController.data.dash!.video!.first.height!, + )); + } + } + @override Widget build(BuildContext context) { final videoHeight = MediaQuery.of(context).size.width * 9 / 16; @@ -493,6 +511,7 @@ class _VideoDetailPageState extends State return PiPSwitcher( childWhenDisabled: childWhenDisabled, childWhenEnabled: childWhenEnabled, + floating: floating, ); } else { return childWhenDisabled; diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index ea30253b..d49bd4ad 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -106,6 +106,7 @@ class SettingBoxKey { static const String enableAutoExit = 'enableAutoExit'; static const String p1080 = 'p1080'; static const String enableCDN = 'enableCDN'; + static const String autoPiP = 'autoPiP'; // youtube 双击快进快退 static const String enableQuickDouble = 'enableQuickDouble';