【问题标题】:Issue with MTAudioProcessingTap on device设备上的 MTAudioProcessingTap 问题
【发布时间】:2013-03-12 01:01:42
【问题描述】:

我正在尝试根据此博客条目中的教程创建一个 MTAudioProcessingTap - http://chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/

问题在于使用各种音频格式。我已经能够使用 M4A 成功创建一个水龙头,但它不适用于 MP3。对我来说甚至更陌生 - 代码可以在两种格式的模拟器上运行,但不能在设备上运行(只有 m4a 有效)。我在我的进程块中收到 OSStatusError 代码 50,如果我尝试使用 AudioBufferList 数据,我将无法访问。我正在使用的点击设置和回调如下。进程块似乎是罪魁祸首(我认为),但我不知道为什么。

更新 - 在休息了一段时间后,第一次似乎非常零星地工作,但只是第一次。我感觉我的音频文件有某种锁定。有谁知道在 unprepare 块中应该做什么来清理?

取消准备块 -

void unprepare(MTAudioProcessingTapRef tap)
{
NSLog(@"Unpreparing the Audio Tap Processor");
}

进程块(将得到 OSStatus 错误 50)-

void process(MTAudioProcessingTapRef tap, CMItemCount numberFrames,
         MTAudioProcessingTapFlags flags, AudioBufferList *bufferListInOut,
         CMItemCount *numberFramesOut, MTAudioProcessingTapFlags *flagsOut)
{
OSStatus err = MTAudioProcessingTapGetSourceAudio(tap, numberFrames, bufferListInOut,
                                                  flagsOut, NULL, numberFramesOut);
if (err) NSLog(@"Error from GetSourceAudio: %ld", err);
}

点击设置 -

NSURL *assetURL = [[NSBundle mainBundle] URLForResource:@"DLP" withExtension:@"mp3"];
assert(assetURL);

// Create the AVAsset
AVAsset *asset = [AVAsset assetWithURL:assetURL];
assert(asset);

// Create the AVPlayerItem
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
assert(playerItem);

assert([asset tracks]);
assert([[asset tracks] count]);

self.player = [AVPlayer playerWithPlayerItem:playerItem];
assert(self.player);

// Continuing on from where we created the AVAsset...
AVAssetTrack *audioTrack = [[asset tracks] objectAtIndex:0];
AVMutableAudioMixInputParameters *inputParams = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];

// Create a processing tap for the input parameters
MTAudioProcessingTapCallbacks callbacks;
callbacks.version = kMTAudioProcessingTapCallbacksVersion_0;
callbacks.clientInfo = (__bridge void *)(self);
callbacks.init = init;
callbacks.prepare = prepare;
callbacks.process = process;
callbacks.unprepare = unprepare;
callbacks.finalize = finalize;

MTAudioProcessingTapRef tap;
// The create function makes a copy of our callbacks struct
OSStatus err = MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks,
                                          kMTAudioProcessingTapCreationFlag_PostEffects, &tap);
if (err || !tap) {
    NSLog(@"Unable to create the Audio Processing Tap");
    return;
}
assert(tap);

// Assign the tap to the input parameters
inputParams.audioTapProcessor = tap;
// Create a new AVAudioMix and assign it to our AVPlayerItem
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
audioMix.inputParameters = @[inputParams];
playerItem.audioMix = audioMix;

// And then we create the AVPlayer with the playerItem, and send it the play message...
[self.player play];

【问题讨论】:

    标签: ios core-audio


    【解决方案1】:

    这显然是 6.0 中的一个错误(我的设备仍在运行)。模拟器是 6.1

    将设备升级到 6.1.2,错误消失了。

    【讨论】:

    • 我一直在尝试使用 MTAudioProcessingTap 并花了几天时间试图弄清楚如何在我完成后将其释放。也许您可以帮助解决这个问题? stackoverflow.com/q/19202306/506796
    猜你喜欢
    • 2011-10-13
    • 2016-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 2021-03-14
    • 2013-05-18
    • 2011-04-12
    相关资源
    最近更新 更多