From 15991ced6a4898c73000ad10aa23729c83a2371e Mon Sep 17 00:00:00 2001 From: orz12 Date: Wed, 6 Mar 2024 10:44:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BD=BB=E5=BA=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=94=BB=E4=B8=AD=E7=94=BB=E5=BC=82=E5=B8=B8=E8=A7=A6=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 2 +- .../com/guozhigq/pilipala/MainActivity.kt | 6 -- .../com/orz12/PiliPalaX/MainActivity.kt | 24 ++++++ lib/pages/video/detail/view.dart | 76 +++++++++++-------- pubspec.lock | 6 +- pubspec.yaml | 2 +- 6 files changed, 72 insertions(+), 44 deletions(-) delete mode 100644 android/app/src/main/kotlin/com/guozhigq/pilipala/MainActivity.kt create mode 100644 android/app/src/main/kotlin/com/orz12/PiliPalaX/MainActivity.kt diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 6ee8d430..2b7dc574 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -45,7 +45,7 @@ android:fullBackupContent="false" tools:replace="android:allowBackup"> late bool autoPiP; final Floating floating = Floating(); // 生命周期监听 - late final AppLifecycleListener _lifecycleListener; + // late final AppLifecycleListener _lifecycleListener; bool isShowing = true; RxBool isFullScreen = false.obs; late StreamSubscription fullScreenStatusListener; + late final MethodChannel onUserLeaveHintListener; @override void initState() { @@ -91,8 +93,16 @@ class _VideoDetailPageState extends State 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 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 plPlayerController!.dispose(); } videoPlayerServiceHandler.onVideoDetailDispose(); - _lifecycleListener.dispose(); + // _lifecycleListener.dispose(); showStatusBar(); super.dispose(); } @@ -275,16 +285,16 @@ class _VideoDetailPageState extends State .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; diff --git a/pubspec.lock b/pubspec.lock index bdd7ffbc..f09b6856 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index 70d29504..f6e212cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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