I\'m trying to set up an AVPlayerViewController completely through storyboards by embedding in a separate View Controller.
Steps:
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.