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()
}