I want to rotate the replay of a video using AVPlayer. Is there a way to rotate it 90 degrees clockwise?
Here's some code:
self.player = AVPlayer(URL: NSURL(fileURLWithPath: dataPath))
playerLayer = AVPlayerLayer.init(player: self.player)
playerLayer.frame = view.bounds
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
view.layer.addSublayer(playerLayer)
player.play()
UPDATE
This one works:
self.player = AVPlayer(URL: NSURL(fileURLWithPath: dataPath))
playerLayer = AVPlayerLayer.init(player: self.player)
playerLayer.setAffineTransform(CGAffineTransformMakeRotation(CGFloat(M_PI))
playerLayer.frame = view.bounds
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
view.layer.addSublayer(playerLayer)
player.play()
Hooni answer in Swift 3 :
let affineTransform = CGAffineTransform(rotationAngle: degreeToRadian(90))
avPlayerLayer.setAffineTransform(affineTransform)
func degreeToRadian(_ x: CGFloat) -> CGFloat {
return .pi * x / 180.0
}
If you are using Objective-C, the code below will help.
#define degreeToRadian(x) (M_PI * x / 180.0)
#define radianToDegree(x) (180.0 * x / M_PI)
- (void)rotateVideoPlayerWithDegree:(CGFloat)degree {
[_playerLayer setAffineTransform:CGAffineTransformMakeRotation(degreeToRadian(degree))];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With