AVPlayer videoGravity AVLayerVideoGravityResizeAspectFill不能正常工作Swift2.2

时间:2016-06-15 13:18:34

标签: swift

请帮我解决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

不起作用。

我还将值设置为AVLayerVideoGravityResizeAVLayerVideoGravityResizeAspect,但结果相似......

0 个答案:

没有答案