If you use the AVPlayerViewController to represent the video, you should be able to use the inherited orientation property of the iterface orientation of the view controller. For instance:
let vc = AVPlayerViewController() vc.supportedInterfaceOrientations = .landscapeRight
I did not have the opportunity to verify this, but it should work, try, and if you encounter any problems, send the code that you have, and I will look and update the answer.
EDIT: Tyti noted that this property is read-only.
You should be able to implement it by extending the AVPlayerController and overriding the supported orientation properties. Create this class in a separate file:
import AVKit class LandscapeAVPlayerController: AVPlayerViewController { override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .landscapeLeft } }
and then in your code above you change the class used as
var playerViewController = LandscapeAVPlayerController()
NOTE 1. In your code above, you create TWO instances of AVPlayerController, you do not need the second.
NOTE 2: Many of the configuration-related methods that you usually override in Swift are now properties in Swift 3, so instead of overriding the method, you override the "getter" for the property
source share