Reputation: 595
I have an app which uses a UISplitViewController
to load a webpage in the Detail View Controller, which has a WKWebView
property. Some of the URLs are links to embedded YouTube videos, and some are direct links to .mp4 files. Either way, the video files are loaded automatically (after tapping for the YouTube videos) into a fullscreen system player, which I assume is an AVPlayerViewController
. I've seen several posts about subclassing AVPlayerViewController
to allow the rotation by implementing supportedInterfaceOrientations
, and other posts which recommended either checking the class of the UIWindow
's rootViewController
presentedViewController
in application: supportedInterfaceOrientationsForWindow:
or checking a variable on the AppDelegate
that was set when the AVPlayerViewController
was presented, but none of these solutions have worked for me because I'm not creating or presenting my own instance of AVPlayerViewController
, so I'm not sure how to allow the rotation to landscape when these videos are playing.
Is there a way I can tell when the system is playing a video in full screen mode, so I can allow the rotation?
Here are links to some of the posts I've seen already:
MPMoviePlayerViewController | Allow landscape mode
Upvotes: 3
Views: 1610
Reputation: 455
I hope u are still need an answer. I have found solution in Swift, but it is simply convertible in Objective C. I found out, that when using WKWebView (maybe UIWebView, too) full screen video is presented in new UIWindow (at least on iOS 10). That window has blank UIViewController and presented AVFullScreenViewController over it.
So, in ur AppDelegate u should implement application:supportedInterfaceOrientationsForWindow:
like this
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if window != self.window, let pvc = window?.rootViewController?.presentedViewController, "\(type(of: pvc))" == "AVFullScreenViewController" {
return pvc.isBeingDismissed ? .portrait : .all
}
return .portrait
}
While AVFullScreenViewController is private API class, u could protect urself and replace "AVFullScreenViewController"
with String(format: "AV%@ViewController", "FullScreen")
Good luck!
Upvotes: 5