请帮我解决AVPlayer问题。我需要在iPhone旋转时调整视频大小(横向)。这是我的代码:
var player: AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
// Load the video from the app bundle.
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("bg_animate", withExtension: "3gp")!
player = AVPlayer(URL: videoURL)
player?.actionAtItemEnd = .None
player?.muted = true
let playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = -1
playerLayer.frame = view.frame
view.layer.addSublayer(playerLayer)
player?.play()
//loop video
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ViewController.loopVideo), name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
}
但是字符串:
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
不起作用。
我还将值设置为AVLayerVideoGravityResize
和AVLayerVideoGravityResizeAspect
,但结果相似......