问题
I want to control the playback speed of audio in AVAudioplayer. Is this possible? If so, how would you do it?
回答1:
Now it is possible to change the playback 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 change it.
See more in the docs.
回答2:
Looks like it works for iOS5 - docs and look at rate.
thanks,
回答3:
Swift 2.0
You can increase the rate by doing this:
player.prepareToPlay()
player.enableRate = true
player.rate = 2.0
player.play()
If you want to loop, you can add this:
player.numberOfLoops = 3
回答4:
Try this -
audioP = try! AVAudioPlayer(contentsOf: URL(fileURLWithPath: selectedPath), fileTypeHint: "caf")
audioP.enableRate = true
audioP.prepareToPlay()
audioP.rate = 1.5
audioP.play()
回答5:
You can't. You can only change the volume not the speed of playback.
I think to do that, you will have to use the much lower level Audio Queue APIs and manipulate the audio stream manually to apply that effect.
回答6:
AVAudioPlayer does not support playback speed setting. Audio Queue Services are quite a pain to use, so that you might want to try OpenAL. See the sound engine from Cocos2D or Finch for examples of how to wrap OpenAL in Objective-C.
回答7:
set enableRate = YES and then you can adjust the rate between 0.1 and 2.0 for slowed down and sped up (1.0 is normal speed)
来源:https://stackoverflow.com/questions/2350657/avaudioplayer-how-to-change-the-playback-speed-of-audio