fix: toggle PiP button closes PiP when already active
This commit is contained in:
@@ -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 {
|
static Future<(bool success, String? error)> enter({int? width, int? height}) async {
|
||||||
if (!_isAvailable) return (false, null);
|
if (!_isAvailable) return (false, null);
|
||||||
final result = await _channel.invokeMethod<Map>('enter', {'width': width, 'height': height});
|
final result = await _channel.invokeMethod<Map>('enter', {'width': width, 'height': height});
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ class VideoPIPManager {
|
|||||||
final supported = await PipService.isSupported();
|
final supported = await PipService.isSupported();
|
||||||
if (!supported) return (false, 'PiP not supported on this device');
|
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 —
|
// Reset video filter to contain mode BEFORE entering PiP (Android only —
|
||||||
// iOS switches VO entirely so the filter is irrelevant)
|
// iOS switches VO entirely so the filter is irrelevant)
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPlayerD
|
|||||||
result(MpvPipController.isSupported)
|
result(MpvPipController.isSupported)
|
||||||
case "enter":
|
case "enter":
|
||||||
enterPip(manual: true, result: result)
|
enterPip(manual: true, result: result)
|
||||||
|
case "exit":
|
||||||
|
pipController?.stopPip()
|
||||||
|
result(nil)
|
||||||
case "setAutoPipReady":
|
case "setAutoPipReady":
|
||||||
if let args = call.arguments as? [String: Any], let ready = args["ready"] as? Bool {
|
if let args = call.arguments as? [String: Any], let ready = args["ready"] as? Bool {
|
||||||
autoPipEnabled = ready
|
autoPipEnabled = ready
|
||||||
@@ -171,6 +174,7 @@ class MpvPlayerPlugin: NSObject, FlutterPlugin, FlutterStreamHandler, MpvPlayerD
|
|||||||
|
|
||||||
enteredPipViaAuto = !manual
|
enteredPipViaAuto = !manual
|
||||||
playerCore.isPipActive = true
|
playerCore.isPipActive = true
|
||||||
|
|
||||||
pip.startPip(metalLayer: metalLayer, window: window, aspectRatio: aspectRatio)
|
pip.startPip(metalLayer: metalLayer, window: window, aspectRatio: aspectRatio)
|
||||||
pipChannel?.invokeMethod("onPipChanged", arguments: true)
|
pipChannel?.invokeMethod("onPipChanged", arguments: true)
|
||||||
result?(["success": true])
|
result?(["success": true])
|
||||||
|
|||||||
Reference in New Issue
Block a user