Merge branch 'fix-pip'
This commit is contained in:
@ -58,9 +58,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
late bool autoExitFullcreen;
|
late bool autoExitFullcreen;
|
||||||
late bool autoPlayEnable;
|
late bool autoPlayEnable;
|
||||||
late bool autoPiP;
|
late bool autoPiP;
|
||||||
final Floating floating = Floating();
|
late Floating floating;
|
||||||
// 生命周期监听
|
|
||||||
late final AppLifecycleListener _lifecycleListener;
|
|
||||||
bool isShowing = true;
|
bool isShowing = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -93,8 +91,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
|
|
||||||
videoSourceInit();
|
videoSourceInit();
|
||||||
appbarStreamListen();
|
appbarStreamListen();
|
||||||
lifecycleListener();
|
|
||||||
fullScreenStatusListener();
|
fullScreenStatusListener();
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
floating = videoDetailController.floating!;
|
||||||
|
autoEnterPip();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取视频资源,初始化播放器
|
// 获取视频资源,初始化播放器
|
||||||
@ -152,6 +153,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
floating.toggleAutoPip(
|
||||||
|
autoEnter: status == PlayerStatus.playing && autoPiP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 继续播放或重新播放
|
// 继续播放或重新播放
|
||||||
@ -170,27 +175,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
videoDetailController.isShowCover.value = false;
|
videoDetailController.isShowCover.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生命周期监听
|
|
||||||
void lifecycleListener() {
|
|
||||||
_lifecycleListener = AppLifecycleListener(
|
|
||||||
onResume: () => _handleTransition('resume'),
|
|
||||||
// 后台
|
|
||||||
onInactive: () => _handleTransition('inactive'),
|
|
||||||
// 在Android和iOS端不生效
|
|
||||||
onHide: () => _handleTransition('hide'),
|
|
||||||
onShow: () => _handleTransition('show'),
|
|
||||||
onPause: () => _handleTransition('pause'),
|
|
||||||
onRestart: () => _handleTransition('restart'),
|
|
||||||
onDetach: () => _handleTransition('detach'),
|
|
||||||
// 只作用于桌面端
|
|
||||||
onExitRequested: () {
|
|
||||||
ScaffoldMessenger.maybeOf(context)
|
|
||||||
?.showSnackBar(const SnackBar(content: Text("拦截应用退出")));
|
|
||||||
return Future.value(AppExitResponse.cancel);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fullScreenStatusListener() {
|
void fullScreenStatusListener() {
|
||||||
plPlayerController?.isFullScreen.listen((bool isFullScreen) {
|
plPlayerController?.isFullScreen.listen((bool isFullScreen) {
|
||||||
if (isFullScreen) {
|
if (isFullScreen) {
|
||||||
@ -210,8 +194,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
videoDetailController.floating!.dispose();
|
videoDetailController.floating!.dispose();
|
||||||
}
|
}
|
||||||
videoPlayerServiceHandler.onVideoDetailDispose();
|
videoPlayerServiceHandler.onVideoDetailDispose();
|
||||||
floating.dispose();
|
if (Platform.isAndroid) {
|
||||||
_lifecycleListener.dispose();
|
floating.toggleAutoPip(autoEnter: false);
|
||||||
|
floating.dispose();
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,29 +250,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
.subscribe(this, ModalRoute.of(context)! as PageRoute);
|
.subscribe(this, ModalRoute.of(context)! as PageRoute);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTransition(String name) {
|
|
||||||
switch (name) {
|
|
||||||
case 'inactive':
|
|
||||||
if (plPlayerController != null &&
|
|
||||||
playerStatus == PlayerStatus.playing) {
|
|
||||||
autoEnterPip();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void autoEnterPip() {
|
void autoEnterPip() {
|
||||||
final String routePath = Get.currentRoute;
|
final String routePath = Get.currentRoute;
|
||||||
final bool isPortrait =
|
if (autoPiP && routePath.startsWith('/video')) {
|
||||||
MediaQuery.of(context).orientation == Orientation.portrait;
|
floating.toggleAutoPip(autoEnter: autoPiP);
|
||||||
|
|
||||||
/// TODO 横屏全屏状态下误触pip
|
|
||||||
if (autoPiP && routePath.startsWith('/video') && isPortrait) {
|
|
||||||
floating.enable(
|
|
||||||
aspectRatio: Rational(
|
|
||||||
videoDetailController.data.dash!.video!.first.width!,
|
|
||||||
videoDetailController.data.dash!.video!.first.height!,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,7 +502,7 @@ packages:
|
|||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: main
|
ref: main
|
||||||
resolved-ref: d2d8421c4d80f6113f832404109853684721e11a
|
resolved-ref: "8e89669eb9341f9980265306e24ef96fdbd3fd08"
|
||||||
url: "https://github.com/guozhigq/floating.git"
|
url: "https://github.com/guozhigq/floating.git"
|
||||||
source: git
|
source: git
|
||||||
version: "2.0.1"
|
version: "2.0.1"
|
||||||
|
Reference in New Issue
Block a user