Change AVPlayer Orientation- Swift

不羁岁月 提交于 2021-01-28 07:29:54

问题


I have looked at multiple ways to change the orientation (rotate 90degrees) of an AVPlayer/AVPlayerLayer. The most common way I found was to do this:

playerLayer.setAffineTransform(CGAffineTransform(rotationAngle: CGFloat.pi / 2))

This what it looks like when I do that (on aspectfill):

As you can see, this doesn't work for me and I think it's because of the changes in xcode and swift over the years.

How would you rotate the AVPlayerlayer 90degrees now?

Thanks in advance!

Code used for AVPlayer:

var post: Post?

var avPlayer: AVPlayer?


override func viewDidLoad() {
    super.viewDidLoad()
    startPlayingVideo()
    // Do any additional setup after loading the view.
}

func startPlayingVideo() {
    // get video onto the avplayer
    guard let videoUrlString = post?.postVideoUrl else { return }
    guard let videoUrl = URL(string: videoUrlString) else { return }
    avPlayer = AVPlayer(url: videoUrl)
    // add the avPlayerLayer
    let playerLayer = AVPlayerLayer(player: avPlayer)
    playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
    playerLayer.frame = self.view.bounds
    self.view.layer.addSublayer(playerLayer)
    //start Playing the video on the avPlayer
    self.avPlayer?.play()        
}

来源:https://stackoverflow.com/questions/64110082/change-avplayer-orientation-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!