Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard ios ios

Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard


In fact, I think it's bug on Apple side.

I found a workaround : set showsPlaybackControls to YES after the AVPlayerViewController.player have been set.

I modify your sample with the following lines and no more Constraint error appears :

@interface ViewController ()@property(weak, nonatomic) AVPlayerViewController * playerViewController;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];    NSURL *url = [[NSURL alloc] initFileURLWithPath: path];    AVPlayer * player = [AVPlayer playerWithURL:url];    self.playerViewController.player = player;    self.playerViewController.showsPlaybackControls = YES;}- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    if ([segue.identifier isEqualToString:@"AVPlayerSegue"]) {        self.playerViewController = segue.destinationViewController;    }}@end

Please note that the file test.mp4 have been added to the project.


I downloaded your code and took a look at it. You are not doing anything wrong. The fact that you can uncheck "Shows Playback Control" seems to indicate that the problem lies with the AVKit framework. I've even tried setting the value to false in the XIB file and then calling [self setShowsPlaybackControls:YES]; after viewDidAppear: with the same results. This is most definitely an Apple bug and you should raise a bug report.


In my case I allow on iPhones only the portrait mode while I want the AVPlayerViewController to have all directions.

In AppDelegate I have code that looks like this:

public func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {    if self.window?.rootViewController?.presentedViewController is AVPlayerViewController {        return .All    }    return Device.current.contains(.iPhone) ? [.Portrait, .PortraitUpsideDown] : .All}

When AVPlayerViewController is presented modally, rotated to landscape and dismissed I'll get a very smiler error stack that some constraints broke.

To workaround I added this code to my RootViewController, which also presents any instance of AVPlayerViewController in my application:

public override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {    if let playerViewController = self.presentedViewController as? AVPlayerViewController {        playerViewController.showsPlaybackControls = false    }    super.dismissViewControllerAnimated(flag, completion: completion)}

Basically I'm catching the moment when the user taps on the dismiss button and use the workaround found in original question post.


matomo