Skip to content

Commit 9f91aa3

Browse files
decisivearmorclaude
andcommitted
fix: Improve PiP support with layer opacity and better debugging
- Set minimal opacity (0.001) to AVPlayerLayer to ensure PiP works - Add comprehensive debugging for layer state and PiP controller - Check and set default bounds if layer has empty bounds - Add isPictureInPicturePossible checks before starting PiP Based on flutter#3500 discussions about PiP requirements. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b6e1d70 commit 9f91aa3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPTextureBasedVideoPlayer.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item
8989
// invisible AVPlayerLayer is used to overwrite the protection of pixel buffers in those streams
9090
// for issue #1, and restore the correct width and height for issue #2.
9191
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
92+
// Set minimal opacity to ensure PiP works properly
93+
self.playerLayer.opacity = 0.001;
9294
[viewProvider.view.layer addSublayer:self.playerLayer];
9395
}
9496
return self;

packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPVideoPlayer.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,25 @@ - (void)setPictureInPictureEnabled:(BOOL)enabled {
555555
}
556556

557557
NSLog(@"Using playerLayer for PiP: %@", layerForPiP);
558+
NSLog(@"Player layer superlayer: %@", layerForPiP.superlayer);
559+
NSLog(@"Player layer bounds: %@", NSStringFromCGRect(layerForPiP.bounds));
560+
NSLog(@"Player layer frame: %@", NSStringFromCGRect(layerForPiP.frame));
561+
NSLog(@"Player: %@", layerForPiP.player);
558562
NSLog(@"isPictureInPictureSupported: %@", [AVPictureInPictureController isPictureInPictureSupported] ? @"YES" : @"NO");
559563

564+
// Ensure the layer has valid bounds
565+
if (CGRectIsEmpty(layerForPiP.bounds)) {
566+
NSLog(@"WARNING: Player layer has empty bounds, setting default size");
567+
layerForPiP.frame = CGRectMake(0, 0, 320, 180);
568+
}
569+
560570
// Create PiP controller
561571
if ([AVPictureInPictureController isPictureInPictureSupported]) {
562572
NSLog(@"Creating AVPictureInPictureController with playerLayer: %@", layerForPiP);
563573
_pipController = [[AVPictureInPictureController alloc] initWithPlayerLayer:layerForPiP];
564574
_pipController.delegate = self;
565575
NSLog(@"PiP controller created: %@", _pipController);
576+
NSLog(@"PiP controller isPictureInPicturePossible: %@", _pipController.isPictureInPicturePossible ? @"YES" : @"NO");
566577
} else {
567578
NSLog(@"PiP is not supported on this device");
568579
}
@@ -571,6 +582,7 @@ - (void)setPictureInPictureEnabled:(BOOL)enabled {
571582
if (_pipController) {
572583
if (enabled && ![_pipController isPictureInPictureActive]) {
573584
NSLog(@"Starting PiP");
585+
NSLog(@"PiP controller isPictureInPicturePossible before start: %@", _pipController.isPictureInPicturePossible ? @"YES" : @"NO");
574586
[_pipController startPictureInPicture];
575587
} else if (!enabled && [_pipController isPictureInPictureActive]) {
576588
NSLog(@"Stopping PiP");

0 commit comments

Comments
 (0)