Akash Patel
Akash Patel

Reputation: 87

How to change the speed of playing audio in AVPlayer?

I am working on AVPlayer. I am done with Pause, Play and fastForward of the playing audio stream. I want to change the playing speed of audio stream while playing. I have searched a lot, but not getting accurate direction. So, help me with this.

Upvotes: 4

Views: 12473

Answers (4)

Shubham Goel
Shubham Goel

Reputation: 2186

You can use "rate"

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

Upvotes: 3

The speed of playback depends upon the value for the rate value; greater than 1.0 is faster, and for slow playback, use less than 1.0.

Upvotes: -3

Solayman Rana
Solayman Rana

Reputation: 331

You can increase or decrease the rate by this single line code:

// change the rate

 Avplayer.playImmediately(atRate: 1.25) 

Upvotes: 6

DogCoffee
DogCoffee

Reputation: 19966

The current rate of playback.

var rate: Float

Docs

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.

Upvotes: 23

Related Questions