简体   繁体   中英

How to change the rate of an AVPlayer video

Hey I'm trying to get a video to play at a different rate (Slower). I can't seem to get it to work.

Code:

This line of code doesn't work

playerLayerView.player?.rate = 0.50

Full Code:

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()

The only why can get it to play is. If I use playImmediately and delete the .Play()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM