如何在AVPlayer Video上禁用自动旋转?

时间:2016-12-22 06:42:58

标签: ios swift avplayer

我有ViewController AVPlayer,但即使我已将肖像设置为info.plist和委托supportedInterfaceOrientationsFor功能中唯一支持的方向,视频也会自动旋转

我没有成功搜索文档。

以下是一些代码:

var videoPlayer = AVPlayerViewController()
var player = AVPlayer.init(url: URL.init(fileURLWithPath: urlString))
videoPlayer?.player = player
videoPlayer?.view.frame = self.view.frame
videoPlayer?.showsPlaybackControls = false

self.present(videoPlayer!, animated: false, completion: {action in
 self.player?.play()
})

1 个答案:

答案 0 :(得分:0)

这可以通过继承AVPlayerViewController并从UIInterfaceOrientationMask.portrait返回supportedInterfaceOrientations来完成,这里是代码。

class PlayerVideoViewController: AVPlayerViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
    return .portrait
}}

感谢Rhythmic Fistman的回答。