Skip to content

Commit

Permalink
fix: pip错误
Browse files Browse the repository at this point in the history
  • Loading branch information
orz12 committed Nov 6, 2024
1 parent e1f958d commit bf4cebd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/pages/setting/play_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _PlaySettingState extends State<PlaySetting> {
),
if (Platform.isAndroid)
SetSwitchItem(
title: '后台画中画(暂时无效)',
title: '后台画中画',
subTitle: '进入后台时以小窗形式(PiP)播放',
leading: const Icon(Icons.picture_in_picture_outlined),
setKey: SettingBoxKey.autoPiP,
Expand All @@ -179,7 +179,7 @@ class _PlaySettingState extends State<PlaySetting> {
}),
if (Platform.isAndroid)
const SetSwitchItem(
title: '画中画不加载弹幕(暂时无效)',
title: '画中画不加载弹幕',
subTitle: '当弹幕开关开启时,小窗屏蔽弹幕以获得较好的体验',
leading: Icon(Icons.comments_disabled_outlined),
setKey: SettingBoxKey.pipNoDanmaku,
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/video/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class VideoDetailController extends GetxController

/// 更新画质、音质
/// TODO 继续进度播放
updatePlayer() {
updatePlayer() async {
if (plPlayerController == null) return;
isShowCover.value = false;
defaultST = plPlayerController!.position.value;
Expand Down
29 changes: 26 additions & 3 deletions lib/pages/video/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
appbarStreamListen();
// lifecycleListener();
autoScreen();

// onUserLeaveHintListener = const MethodChannel("onUserLeaveHint");
// onUserLeaveHintListener.setMethodCallHandler((call) async {
// if (call.method == 'onUserLeaveHint') {
Expand Down Expand Up @@ -145,7 +146,28 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.addStatusLister(playerListener);
listenFullScreenStatus();
await plPlayerController!.autoEnterFullscreen();
// autoEnterPip();
Future.wait([_futureBuilderFuture]).then((result) {
autoEnterPip();
});
}
}

void autoEnterPip() {
String top = Get.currentRoute;
if (autoPiP && (top.startsWith('/video') || top.startsWith('/live'))) {
FlPiP().enable(
ios: FlPiPiOSConfig(
enabledWhenBackground: true,
videoPath: videoDetailController.videoUrl,
audioPath: videoDetailController.audioUrl,
packageName: null),
android: FlPiPAndroidConfig(
enabledWhenBackground: true,
aspectRatio: Rational(
videoDetailController.data.dash!.video!.first.width!,
videoDetailController.data.dash!.video!.first.height!,
),
));
}
}

Expand Down Expand Up @@ -207,7 +229,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
listenFullScreenStatus();
await plPlayerController!.autoEnterFullscreen();
videoDetailController.autoPlay.value = true;
// autoEnterPip();
autoEnterPip();
}

// // 生命周期监听
Expand Down Expand Up @@ -404,6 +426,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.videoController == null
? nil
: PLVideoPlayer(
key: Key(heroTag),
controller: plPlayerController!,
videoIntroController:
videoDetailController.videoType == SearchType.video
Expand Down Expand Up @@ -1130,6 +1153,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
() => !videoDetailController.autoPlay.value
? const SizedBox()
: PLVideoPlayer(
key: Key(heroTag),
controller: plPlayerController!,
videoIntroController:
videoDetailController.videoType == SearchType.video
Expand Down Expand Up @@ -1157,7 +1181,6 @@ class _VideoDetailPageState extends State<VideoDetailPage>
),
);
Widget autoChoose(Widget childWhenDisabled) {

return PiPBuilder(builder: (PiPStatusInfo? statusInfo) {
print("PiPStatusInfo${statusInfo?.status}");
switch (statusInfo?.status) {
Expand Down
6 changes: 2 additions & 4 deletions lib/pages/video/widgets/header_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1624,10 +1624,8 @@ class _HeaderControlState extends State<HeaderControl> {
widget.controller!.controls = false;
FlPiP().enable(
ios: FlPiPiOSConfig(
videoPath:
widget.controller!.dataSource.videoSource ?? "",
audioPath:
widget.controller!.dataSource.audioSource ?? "",
videoPath: widget.videoDetailCtr!.videoUrl,
audioPath: widget.videoDetailCtr!.audioUrl,
packageName: null),
android: FlPiPAndroidConfig(
aspectRatio: Rational(
Expand Down

0 comments on commit bf4cebd

Please sign in to comment.