fix: toggle PiP button closes PiP when already active

This commit is contained in:
edde746
2026-03-06 03:08:28 +01:00
parent f7ca80de77
commit 985ba5d2c7
3 changed files with 15 additions and 0 deletions
+5
View File
@@ -53,6 +53,11 @@ class PipService {
});
}
static Future<void> exit() async {
if (!_isAvailable) return;
await _channel.invokeMethod('exit');
}
static Future<(bool success, String? error)> enter({int? width, int? height}) async {
if (!_isAvailable) return (false, null);
final result = await _channel.invokeMethod<Map>('enter', {'width': width, 'height': height});
+6
View File
@@ -61,6 +61,12 @@ class VideoPIPManager {
final supported = await PipService.isSupported();
if (!supported) return (false, 'PiP not supported on this device');
// If PiP is already active, exit it
if (isPipActive.value) {
await PipService.exit();
return (true, null);
}
// Reset video filter to contain mode BEFORE entering PiP (Android only —
// iOS switches VO entirely so the filter is irrelevant)
if (Platform.isAndroid) {
@@ -117,6 +117,9 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPlayerD
result(MpvPipController.isSupported)
case "enter":
enterPip(manual: true, result: result)
case "exit":
pipController?.stopPip()
result(nil)
case "setAutoPipReady":
if let args = call.arguments as? [String: Any], let ready = args["ready"] as? Bool {
autoPipEnabled = ready
@@ -171,6 +174,7 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPlayerD
enteredPipViaAuto = !manual
playerCore.isPipActive = true
pip.startPip(metalLayer: metalLayer, window: window, aspectRatio: aspectRatio)
pipChannel?.invokeMethod("onPipChanged", arguments: true)
result?(["success": true])