如何更改 AVPlayer 中播放音频的速度?

How to change the speed of playing audio in AVPlayer?

我正在研究 AVPlayer。我已完成播放音频流的 PausePlayfastForward。我想在播放时更改音频流的播放速度。我搜索了很多,但没有得到准确的方向。所以,帮我解决这个问题。

当前播放速率。

var rate: Float

文档

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayer_Class/#//apple_ref/occ/instp/AVPlayer/rate

A value of 0.0 means pauses the video, while a value of 1.0 play at the natural rate of the current item. Rates other than 0.0 and 1.0 can be used if the associated player item returns YES for the AVPlayerItem properties canPlaySlowForward or canPlayFastForward. Negative rate value ranges are supported if the player item returns YES for the canPlayReverse, canPlaySlowReverse, and canPlayFastReverse properties.

播放速度取决于rate值;大于 1.0 更快,对于慢速播放,使用小于 1.0.

您可以通过以下单行代码增加或减少费率:

// change the rate

 Avplayer.playImmediately(atRate: 1.25) 

您可以使用“评分”

private var player: AVPlayer?
....
player?.rate = 1.25