fix: 彻底修复画中画异常触发

This commit is contained in:
orz12
2024-03-06 10:44:16 +08:00
parent 8135bde6b1
commit 15991ced6a
6 changed files with 72 additions and 44 deletions

View File

@@ -45,7 +45,7 @@
android:fullBackupContent="false"
tools:replace="android:allowBackup">
<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:name="com.orz12.PiliPalaX.MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"

View File

@@ -1,6 +0,0 @@
package com.orz12.PiliPalaX
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}

View File

@@ -0,0 +1,24 @@
package com.orz12.PiliPalaX
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import com.ryanheise.audioservice.AudioServiceActivity
class MainActivity : AudioServiceActivity() {
private lateinit var methodChannel: MethodChannel
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
methodChannel = MethodChannel(flutterEngine!!.getDartExecutor()!!.getBinaryMessenger(), CHANNEL)
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
methodChannel.invokeMethod("onUserLeaveHint", null)
}
companion object {
private const val CHANNEL = "onUserLeaveHint"
}
}

View File

@@ -5,6 +5,7 @@ import 'dart:ui';
import 'package:auto_orientation/auto_orientation.dart';
import 'package:floating/floating.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
@@ -58,10 +59,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
late bool autoPiP;
final Floating floating = Floating();
// 生命周期监听
late final AppLifecycleListener _lifecycleListener;
// late final AppLifecycleListener _lifecycleListener;
bool isShowing = true;
RxBool isFullScreen = false.obs;
late StreamSubscription<bool> fullScreenStatusListener;
late final MethodChannel onUserLeaveHintListener;
@override
void initState() {
@@ -91,8 +93,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false);
videoSourceInit();
appbarStreamListen();
lifecycleListener();
// lifecycleListener();
autoScreen();
onUserLeaveHintListener = const MethodChannel("onUserLeaveHint");
onUserLeaveHintListener.setMethodCallHandler((call) async {
if (call.method == 'onUserLeaveHint') {
if (autoPiP) {
autoEnterPip();
}
}
});
}
// 获取视频资源,初始化播放器
@@ -164,26 +174,26 @@ class _VideoDetailPageState extends State<VideoDetailPage>
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 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 listenFullScreenStatus() {
fullScreenStatusListener =
@@ -220,7 +230,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.dispose();
}
videoPlayerServiceHandler.onVideoDetailDispose();
_lifecycleListener.dispose();
// _lifecycleListener.dispose();
showStatusBar();
super.dispose();
}
@@ -275,16 +285,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
.subscribe(this, ModalRoute.of(context)! as PageRoute);
}
void _handleTransition(String name) {
switch (name) {
case 'inactive':
if (plPlayerController != null &&
playerStatus == PlayerStatus.playing) {
autoEnterPip();
}
break;
}
}
// void _handleTransition(String name) {
// switch (name) {
// case 'inactive':
// if (plPlayerController != null &&
// playerStatus == PlayerStatus.playing) {
// autoEnterPip();
// }
// break;
// }
// }
void autoEnterPip() {
final String routePath = Get.currentRoute;

View File

@@ -502,10 +502,10 @@ packages:
description:
path: "."
ref: main
resolved-ref: d2d8421c4d80f6113f832404109853684721e11a
url: "https://github.com/guozhigq/floating.git"
resolved-ref: "754e5c4e565f29cd095c0e444ac796019ff1acc2"
url: "https://github.com/wrbl606/floating.git"
source: git
version: "2.0.1"
version: "2.0.2"
flutter:
dependency: "direct main"
description: flutter

View File

@@ -124,7 +124,7 @@ dependencies:
# pip
floating:
git:
url: https://github.com/guozhigq/floating.git
url: https://github.com/wrbl606/floating.git
ref: main
# html解析
html: ^0.15.4