feat: 应用切换至后台自动画中画 issues #212
This commit is contained in:
@ -85,6 +85,12 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
setKey: SettingBoxKey.enableBackgroundPlay,
|
||||
defaultVal: false,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '自动PiP播放',
|
||||
subTitle: 'app切换至后台时画中画播放',
|
||||
setKey: SettingBoxKey.autoPiP,
|
||||
defaultVal: false,
|
||||
),
|
||||
const SetSwitchItem(
|
||||
title: '自动全屏',
|
||||
subTitle: '视频开始播放时进入全屏',
|
||||
|
@ -32,7 +32,7 @@ class VideoDetailPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
with TickerProviderStateMixin, RouteAware {
|
||||
with TickerProviderStateMixin, RouteAware, WidgetsBindingObserver {
|
||||
late VideoDetailController videoDetailController;
|
||||
PlPlayerController? plPlayerController;
|
||||
final ScrollController _extendNestCtr = ScrollController();
|
||||
@ -52,6 +52,8 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
// 自动退出全屏
|
||||
late bool autoExitFullcreen;
|
||||
late bool autoPlayEnable;
|
||||
late bool autoPiP;
|
||||
final floating = Floating();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -65,8 +67,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
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<VideoDetailPage>
|
||||
if (videoDetailController.floating != null) {
|
||||
videoDetailController.floating!.dispose();
|
||||
}
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
floating.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -195,6 +202,17 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
||||
.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<VideoDetailPage>
|
||||
return PiPSwitcher(
|
||||
childWhenDisabled: childWhenDisabled,
|
||||
childWhenEnabled: childWhenEnabled,
|
||||
floating: floating,
|
||||
);
|
||||
} else {
|
||||
return childWhenDisabled;
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user