我想使用AVPlayer旋转视频的重播。有没有办法顺时针旋转90度? 这是一些代码:
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()
更新
这个有效:
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()
答案 0 :(得分:4)
如果您使用的是Objective-C,则以下代码会有所帮助。
#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))];
}
答案 1 :(得分:3)
Hooni在Swift 3中回答:
let affineTransform = CGAffineTransform(rotationAngle: degreeToRadian(90))
avPlayerLayer.setAffineTransform(affineTransform)
func degreeToRadian(_ x: CGFloat) -> CGFloat {
return .pi * x / 180.0
}