Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 247
Akash Patel Avatar asked Oct 23 '25 19:10

Akash Patel


2 Answers

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.

like image 87
DogCoffee Avatar answered Oct 26 '25 08:10

DogCoffee


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

// change the rate

 Avplayer.playImmediately(atRate: 1.25) 
like image 37
Solayman Rana Avatar answered Oct 26 '25 09:10

Solayman Rana