[ACCEPTED]-AVAudioPlayer: How to Change the Playback Speed of Audio?-avaudioplayer

Accepted answer
Score: 35

Now it is possible to change the playback 2 speed.

Sample code:

player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&err];
player.volume = 0.4f;
player.enableRate = YES; //<--
[player prepareToPlay];
[player setNumberOfLoops:0];
player.rate = 2.0f; //<-- Playback Speed
[player play];

enableRate is set to YES and you can 1 change it.

See more in the docs.

Score: 18

Swift 2 - Swift 5

You can increase the rate by doing this:

player.enableRate = true
player.prepareToPlay()
player.rate = 2.0
player.play()

If you want to loop, you can add this:

player.numberOfLoops = 3

0

Score: 3

Try this -

audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
        audioP.enableRate = true
        audioP.prepareToPlay()
        audioP.rate = 1.5
        audioP.play()

0

Score: 1

You can't. You can only change the volume 4 not the speed of playback.

I think to do 3 that, you will have to use the much lower 2 level Audio Queue APIs and manipulate the audio stream 1 manually to apply that effect.

Score: 1

set enableRate = YES and then you can adjust 2 the rate between 0.1 and 2.0 for slowed 1 down and sped up (1.0 is normal speed)

Score: 0

AVAudioPlayer does not support playback 5 speed setting. Audio Queue Services are 4 quite a pain to use, so that you might want 3 to try OpenAL. See the sound engine from 2 Cocos2D or Finch for examples of how to wrap OpenAL 1 in Objective-C.

More Related questions