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" android:fullBackupContent="false"
tools:replace="android:allowBackup"> tools:replace="android:allowBackup">
<activity <activity
android:name="com.ryanheise.audioservice.AudioServiceActivity" android:name="com.orz12.PiliPalaX.MainActivity"
android:exported="true" android:exported="true"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/LaunchTheme" 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:auto_orientation/auto_orientation.dart';
import 'package:floating/floating.dart'; import 'package:floating/floating.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -58,10 +59,11 @@ class _VideoDetailPageState extends State<VideoDetailPage>
late bool autoPiP; late bool autoPiP;
final Floating floating = Floating(); final Floating floating = Floating();
// 生命周期监听 // 生命周期监听
late final AppLifecycleListener _lifecycleListener; // late final AppLifecycleListener _lifecycleListener;
bool isShowing = true; bool isShowing = true;
RxBool isFullScreen = false.obs; RxBool isFullScreen = false.obs;
late StreamSubscription<bool> fullScreenStatusListener; late StreamSubscription<bool> fullScreenStatusListener;
late final MethodChannel onUserLeaveHintListener;
@override @override
void initState() { void initState() {
@@ -91,8 +93,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false); autoPiP = setting.get(SettingBoxKey.autoPiP, defaultValue: false);
videoSourceInit(); videoSourceInit();
appbarStreamListen(); appbarStreamListen();
lifecycleListener(); // lifecycleListener();
autoScreen(); 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; videoDetailController.isShowCover.value = false;
} }
// 生命周期监听 // // 生命周期监听
void lifecycleListener() { // void lifecycleListener() {
_lifecycleListener = AppLifecycleListener( // _lifecycleListener = AppLifecycleListener(
onResume: () => _handleTransition('resume'), // onResume: () => _handleTransition('resume'),
// 后台 // // 后台
onInactive: () => _handleTransition('inactive'), // onInactive: () => _handleTransition('inactive'),
// 在Android和iOS端不生效 // // 在Android和iOS端不生效
onHide: () => _handleTransition('hide'), // onHide: () => _handleTransition('hide'),
onShow: () => _handleTransition('show'), // onShow: () => _handleTransition('show'),
onPause: () => _handleTransition('pause'), // onPause: () => _handleTransition('pause'),
onRestart: () => _handleTransition('restart'), // onRestart: () => _handleTransition('restart'),
onDetach: () => _handleTransition('detach'), // onDetach: () => _handleTransition('detach'),
// 只作用于桌面端 // // 只作用于桌面端
onExitRequested: () { // onExitRequested: () {
ScaffoldMessenger.maybeOf(context) // ScaffoldMessenger.maybeOf(context)
?.showSnackBar(const SnackBar(content: Text("拦截应用退出"))); // ?.showSnackBar(const SnackBar(content: Text("拦截应用退出")));
return Future.value(AppExitResponse.cancel); // return Future.value(AppExitResponse.cancel);
}, // },
); // );
} // }
void listenFullScreenStatus() { void listenFullScreenStatus() {
fullScreenStatusListener = fullScreenStatusListener =
@@ -220,7 +230,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
plPlayerController!.dispose(); plPlayerController!.dispose();
} }
videoPlayerServiceHandler.onVideoDetailDispose(); videoPlayerServiceHandler.onVideoDetailDispose();
_lifecycleListener.dispose(); // _lifecycleListener.dispose();
showStatusBar(); showStatusBar();
super.dispose(); super.dispose();
} }
@@ -275,16 +285,16 @@ class _VideoDetailPageState extends State<VideoDetailPage>
.subscribe(this, ModalRoute.of(context)! as PageRoute); .subscribe(this, ModalRoute.of(context)! as PageRoute);
} }
void _handleTransition(String name) { // void _handleTransition(String name) {
switch (name) { // switch (name) {
case 'inactive': // case 'inactive':
if (plPlayerController != null && // if (plPlayerController != null &&
playerStatus == PlayerStatus.playing) { // playerStatus == PlayerStatus.playing) {
autoEnterPip(); // autoEnterPip();
} // }
break; // break;
} // }
} // }
void autoEnterPip() { void autoEnterPip() {
final String routePath = Get.currentRoute; final String routePath = Get.currentRoute;

View File

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

View File

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