ios - AVQueuePlayer 设置音频的 Tempo

标签 ios objective-c audio avqueueplayer tempo

我正在使用 AVQueuePlayer用于播放本地保存的多个音频。
供引用,请检查以下代码,

for (int j = 0; j < arrPlayData.count; j++) {
                  
    path =[[NSBundle mainBundle] pathForResource:[[arrPlayData objectAtIndex:j] valueForKey:AUDIO_NAME] ofType:@"wav"];
    item = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:path]];
    if (_queuePlayer == nil) {
        _queuePlayer = [[AVQueuePlayer alloc] initWithPlayerItem:item];
     } else{
        [_queuePlayer insertItem:item afterItem:nil];
     }
}
[_queuePlayer setVolume:1.0];
[_queuePlayer play];
这工作正常,
现在我想为生成的音频应用 0 到 240 之间的速度,如下图所示。
enter image description here
我知道 setRate:属性并将其应用如下,
[_queuePlayer setRate:sldValue/240.0];
在这里,sldValue 是从上面的 slider 中选择的值。在这里,如果我从 slider 中选择 240,则速率变为 1(以正常形式播放音频 - 原始格式)。当我从 slider 中选择向下值时,它会减慢音频速度。
我的问题是如何提高音频速度然后正常播放。或者这个节奏是如何运作的?
非常感谢任何帮助。提前致谢!

最佳答案

[_queuePlayer setRate:sldValue/245.0];

Here, sldValue is selected value from above slider. Here if I select 240 from slider then rate becomes 1(Which plays audio in normal form - Original one). And as I select down value from slider then it will slow down the audio speed.



那是因为这正是你所要求的。想想看。如果 slider 在 240,那么 sldValue/245.0大约是1,这意味着正常,就像你说的那样。如果你向下滑动,假设是 120,那么 sldValue/245.0大约是 1/2,也就是半速。

该程序正在执行您告诉它执行的操作。如果那不是你想要的,那就不要这么说!

此外,您需要设置 audioTimePitchAlgorithm您的播放器项目的适当性,否则您将无法获得全方位的费率。见:AVPlayer rate property does not work?

关于ios - AVQueuePlayer 设置音频的 Tempo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35932582/

相关文章:

ios - 如何计算UIViewController内部内容的高度?

ios - 如何在 Objective C 中调整 UITableView 行高

ios - 在 Xcode 中按下按钮时如何转到相同的 View Controller ?

iphone - 使用音频队列的iPhone节拍器

javascript - 无法在我的 Flash/HTML5/Canvas 项目中播放音频

objective-c - 如何播放选择器选择的许多声音?

ios - GridView 单元格向上滚动到 iOS 7 中的状态栏

ios - 在 peoplePicker NavigationController 中选择人员后显示自定义 View

ios - 'NSInternalInconsistencyException',原因 : 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'

iphone - 在表格单元格中输入文本数据,每个单元格中没有 UITextField