AVAudioPlayer速率 [英] AVAudioPlayer rate

查看:136
本文介绍了AVAudioPlayer速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图在iOS 5.1.1中以不同的速率播放声音文件,而且绝对没有运气.到目前为止,我已经尝试设置AVAudioPlayer的速率:

So I'm trying to play a sound file at a different rate in iOS 5.1.1, and am having absolutely no luck. So far I have tried setting the rate of the AVAudioPlayer:

player = [[AVAudioPlayer alloc] initWithContentsOfURL:referenceURL error:&error];
player.enableRate = YES;
player.rate = 1.5;
player.numberOfLoops = 0;
player.delegate = self;
[player prepareToPlay];
[player play];

完全没有运气,声音会播放,但忽略了我给它的速度.我也尝试过AVPlayer:

with no luck at all, the sound plays but just ignores the rate I give it. I have also tried AVPlayer:

avPlayer = [[AVPlayer alloc] initWithURL:referenceURL];
avPlayer.rate = 0.5;
[avPlayer play];

再次播放,但只是忽略了我设置的速度.我尝试了许多不同的音频文件,但是出于这个主题,我从以下目录中选择了Rooster-mono.wav: http://sig.sapp.org/sounds/wave/

Again, it plays but just ignores the rate I set. I have tried a number of different audio files but for the sake of this thread I selected Rooster-mono.wav from this catalogue: http://sig.sapp.org/sounds/wave/

在iOS 5.1.1上更改播放速率是否有人成功?还是有人知道我在这里想念的东西吗?

Has anybody had any success with changing the playback rate on iOS 5.1.1? Or does anybody know what I am missing here?

我这样做是为了稍微改变一些样本的音调,我意识到我可以使用RemoteIO或类似的方法来做到这一点,但这似乎完全超出了我想要达到的目标(简单的回放速率调整).

I am doing this to change the pitch slightly of some of my samples, I realise I could do this by using RemoteIO or something similar but that seems total overkill for what I am trying to achieve (a simple playback rate adjustment).

推荐答案

这是一些我知道有效的代码,只是在我一直在开发的应用程序中对其进行了重新测试.如您所述,使用setEnableRate:setRate:仅在iOS 5.0及更高版本上有效.所以我用respondsToSelector:在设备上测试设备是否将接受请求:

here is some code that i know works, just re-tested in an app i've been working on. as you mention, using setEnableRate: and setRate: will only work with iOS 5.0 and above. so i use respondsToSelector: to test on the device whether or not the device will accept the request:

_noticeAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Rooster-mono" ofType:@"wav"]]
                                                      error:nil];;
if ([_noticeAudio respondsToSelector:@selector(setEnableRate:)])
    _noticeAudio.enableRate = YES;
if ([_noticeAudio respondsToSelector:@selector(setRate:)])
    _noticeAudio.rate = 2.0;

在iOS 5设备上运行,它将成功执行双倍速率.在iOS 4.3上运行,它将以正常速度播放.

running on an iOS 5 device, it performs the double-rate successfully. running on iOS 4.3, it plays it at normal speed.

因此,只有在设备上装有iOS 5的情况下,您才能获得适当的费率.

so, the only way you'll get the proper rate is if your device has iOS 5 on it.

这篇关于AVAudioPlayer速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆