I'm looking for a way to force a AVplayer (Video) to only display itself in landscape mode (home button on the left). Is this possible?
EDIT: Attempted to add playerViewController.supportedInterfaceOrientations = .landscapeLeft
Got error message "Cannot assign to property: 'supportedInterfaceOrientations' is a get-only property"
import AVKit
import AVFoundation
UIViewController {
var videoPlayer = AVPlayer()
var playerViewController = AVPlayerViewController()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
play()
}
func play() {
playerViewController.supportedInterfaceOrientations = .landscapeLeft
let moviePath = Bundle.main.path(forResource: "full video", ofType: "mov")
if let path = moviePath {
let url = NSURL.fileURL(withPath: path)
let videoPlayer = AVPlayer(url: url)
let playerViewController = AVPlayerViewController()
playerViewController.player = videoPlayer
self.present(playerViewController, animated: true) {
if let validPlayer = playerViewController.player {
validPlayer.play()
playerViewController.showsPlaybackControls = false
}
}
}
}
}
EDIT: Attempted to add new subclass of AVPlayerViewController
import UIKit
import AVFoundation
import AVKit
class LandscapeVideoControllerViewController: AVPlayerViewController {
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .landscapeLeft
}
}
but getting error message "Method does not override any method from its superclass"