How to force landscape mode in AVPlayer?
If you are using the AVPlayerViewController
to present the video you should be able to use the inherited supported iterface orientations property of the view controller, Like so:
let vc = AVPlayerViewController()
vc.supportedInterfaceOrientations = .landscapeRight
// other configs and code to present VC
I haven't had chance to test this but it should work, give it a try and if your having any issues please post the code you have and I'll have a look and update the answer.
EDIT: Taytee pointed out that this is a read only property.
You should be be able to implement it by extending the AVPlayerController and overriding the supported orientation properties, Create this class in a seperate file:
import AVKit
class LandscapeAVPlayerController: AVPlayerViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeLeft
}
}
and then in your code above, you'd change the class used like
var playerViewController = LandscapeAVPlayerController()
NOTE 1: In your code above you are creating TWO instances of AVPlayerController, you dont need the second one.
NOTE 2: Alot of the config related methods you would normally override in Swift are now properties in Swift 3, so instead of overriding the method, you override the 'getter' for the property