mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
@@ -1,5 +1,6 @@
|
||||
package com.example.piliplus
|
||||
|
||||
import android.app.PictureInPictureParams
|
||||
import android.app.SearchManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
@@ -102,6 +103,14 @@ class MainActivity : AudioServiceActivity() {
|
||||
} catch (_: Throwable) {}
|
||||
result.success(false)
|
||||
}
|
||||
"setPipAutoEnterEnabled" -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
val params = PictureInPictureParams.Builder()
|
||||
.setAutoEnterEnabled(call.argument<Boolean>("autoEnable") ?: false)
|
||||
.build()
|
||||
setPictureInPictureParams(params)
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,9 +199,9 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
|
||||
// 播放器状态监听
|
||||
Future<void> playerListener(PlayerStatus status) async {
|
||||
bool isPlaying = status == PlayerStatus.playing;
|
||||
try {
|
||||
if (videoDetailController.scrollCtr.hasClients) {
|
||||
bool isPlaying = status == PlayerStatus.playing;
|
||||
if (isPlaying) {
|
||||
if (!videoDetailController.isExpanding &&
|
||||
videoDetailController.scrollCtr.offset != 0 &&
|
||||
@@ -275,6 +275,17 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Platform.isAndroid &&
|
||||
plPlayerController!.autoPiP &&
|
||||
await Utils.sdkInt >= 12) {
|
||||
if (isPlaying) {
|
||||
plPlayerController!.enterPip(isAuto: true);
|
||||
} else {
|
||||
Utils.channel.invokeMethod('setPipAutoEnterEnabled', {
|
||||
'autoEnable': false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 继续播放或重新播放
|
||||
|
||||
@@ -309,10 +309,11 @@ class PlPlayerController {
|
||||
}
|
||||
}
|
||||
|
||||
void enterPip() {
|
||||
void enterPip({bool isAuto = false}) {
|
||||
if (videoController != null) {
|
||||
final state = videoController!.player.state;
|
||||
PageUtils.enterPip(
|
||||
isAuto: isAuto,
|
||||
width: state.width ?? width,
|
||||
height: state.height ?? height,
|
||||
);
|
||||
@@ -556,15 +557,19 @@ class PlPlayerController {
|
||||
}
|
||||
|
||||
if (Platform.isAndroid && autoPiP) {
|
||||
Utils.sdkInt.then((sdkInt) {
|
||||
if (sdkInt < 12) {
|
||||
Utils.channel.setMethodCallHandler((call) async {
|
||||
if (call.method == 'onUserLeaveHint') {
|
||||
if (playerStatus.status.value == PlayerStatus.playing &&
|
||||
if (playerStatus.playing &&
|
||||
Get.currentRoute.startsWith('/video')) {
|
||||
enterPip();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
|
||||
// if (status == PlayerStatus.playing) {
|
||||
|
||||
@@ -350,20 +350,21 @@ abstract class PageUtils {
|
||||
);
|
||||
}
|
||||
|
||||
static void enterPip({int? width, int? height}) {
|
||||
static void enterPip({int? width, int? height, bool isAuto = false}) {
|
||||
if (width != null && height != null) {
|
||||
Rational aspectRatio = Rational(width, height);
|
||||
Floating().enable(
|
||||
EnableManual(
|
||||
aspectRatio: aspectRatio.fitsInAndroidRequirements
|
||||
aspectRatio = aspectRatio.fitsInAndroidRequirements
|
||||
? aspectRatio
|
||||
: height > width
|
||||
? const Rational.vertical()
|
||||
: const Rational.landscape(),
|
||||
),
|
||||
: const Rational.landscape();
|
||||
Floating().enable(
|
||||
isAuto
|
||||
? AutoEnable(aspectRatio: aspectRatio)
|
||||
: EnableManual(aspectRatio: aspectRatio),
|
||||
);
|
||||
} else {
|
||||
Floating().enable(const EnableManual());
|
||||
Floating().enable(isAuto ? const AutoEnable() : const EnableManual());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user