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
|
package com.example.piliplus
|
||||||
|
|
||||||
|
import android.app.PictureInPictureParams
|
||||||
import android.app.SearchManager
|
import android.app.SearchManager
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -102,6 +103,14 @@ class MainActivity : AudioServiceActivity() {
|
|||||||
} catch (_: Throwable) {}
|
} catch (_: Throwable) {}
|
||||||
result.success(false)
|
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()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,9 +199,9 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
|
|||||||
|
|
||||||
// 播放器状态监听
|
// 播放器状态监听
|
||||||
Future<void> playerListener(PlayerStatus status) async {
|
Future<void> playerListener(PlayerStatus status) async {
|
||||||
|
bool isPlaying = status == PlayerStatus.playing;
|
||||||
try {
|
try {
|
||||||
if (videoDetailController.scrollCtr.hasClients) {
|
if (videoDetailController.scrollCtr.hasClients) {
|
||||||
bool isPlaying = status == PlayerStatus.playing;
|
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
if (!videoDetailController.isExpanding &&
|
if (!videoDetailController.isExpanding &&
|
||||||
videoDetailController.scrollCtr.offset != 0 &&
|
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) {
|
if (videoController != null) {
|
||||||
final state = videoController!.player.state;
|
final state = videoController!.player.state;
|
||||||
PageUtils.enterPip(
|
PageUtils.enterPip(
|
||||||
|
isAuto: isAuto,
|
||||||
width: state.width ?? width,
|
width: state.width ?? width,
|
||||||
height: state.height ?? height,
|
height: state.height ?? height,
|
||||||
);
|
);
|
||||||
@@ -556,12 +557,16 @@ class PlPlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Platform.isAndroid && autoPiP) {
|
if (Platform.isAndroid && autoPiP) {
|
||||||
Utils.channel.setMethodCallHandler((call) async {
|
Utils.sdkInt.then((sdkInt) {
|
||||||
if (call.method == 'onUserLeaveHint') {
|
if (sdkInt < 12) {
|
||||||
if (playerStatus.status.value == PlayerStatus.playing &&
|
Utils.channel.setMethodCallHandler((call) async {
|
||||||
Get.currentRoute.startsWith('/video')) {
|
if (call.method == 'onUserLeaveHint') {
|
||||||
enterPip();
|
if (playerStatus.playing &&
|
||||||
}
|
Get.currentRoute.startsWith('/video')) {
|
||||||
|
enterPip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
if (width != null && height != null) {
|
||||||
Rational aspectRatio = Rational(width, height);
|
Rational aspectRatio = Rational(width, height);
|
||||||
|
aspectRatio = aspectRatio.fitsInAndroidRequirements
|
||||||
|
? aspectRatio
|
||||||
|
: height > width
|
||||||
|
? const Rational.vertical()
|
||||||
|
: const Rational.landscape();
|
||||||
Floating().enable(
|
Floating().enable(
|
||||||
EnableManual(
|
isAuto
|
||||||
aspectRatio: aspectRatio.fitsInAndroidRequirements
|
? AutoEnable(aspectRatio: aspectRatio)
|
||||||
? aspectRatio
|
: EnableManual(aspectRatio: aspectRatio),
|
||||||
: height > width
|
|
||||||
? const Rational.vertical()
|
|
||||||
: const Rational.landscape(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Floating().enable(const EnableManual());
|
Floating().enable(isAuto ? const AutoEnable() : const EnableManual());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user