如何更改AVPlayer视频的速率

时间:2017-07-07 04:12:35

标签: ios swift xcode avplayer

嘿我试图以不同的速度播放视频(较慢)。我似乎无法让它发挥作用。

代码:

这行代码不起作用

playerLayerView.player?.rate = 0.50

完整代码:

var player = AVPlayer()
var playerLayer = AVPlayerLayer()
var playerLayerView = AVPlayerViewController()


let path = Bundle.main.path(forResource: "Video", ofType: "mov")
let prl = URL(fileURLWithPath: path!)
player = AVPlayer(url: prl)
playerLayerView.player = player
playerLayerView.view.frame = CGRect(.frame.width * 0.0, .frame.height * 0.0, .frame.width, .frame.height)
playerLayerView.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue
playerLayerView.player?.rate = 0.50
player.seek(to: kCMTimeZero)
player.isMuted = false
page.insertSubview(playerLayerView.view, at: 0)
playerLayerView.player?.play()

唯一能让它发挥作用的原因是。如果我使用playImmediately并删除.​​Play()

player.playImmediately(atRate: 0.50) //.rate = 1.50 //0.50, 0.67, 0.80, 1.0, 1.25, 1.50, and 2.0

1 个答案:

答案 0 :(得分:4)

在playerLayerView.player?。play()调用此方法后设置rate属性。