AVAudioPlayer速率

编程入门 行业动态 更新时间:2024-10-28 12:18:26
本文介绍了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: sig.sapp/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: sig.sapp/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速率

本文发布于:2023-11-26 16:03:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634337.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:速率   AVAudioPlayer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!