AVPlayer播放单声道audio立体声 – >单声道

在我的iPad / iPhone应用程序中,我使用AVPlayer播放video。 video文件有一个立体声音轨,但我只需要在单声道播放此音轨的一个通道。 部署目标是iOS 6.我怎样才能做到这一点? 非常感谢你的帮助。

我现在终于find了这个问题的答案 – 至less在iOS 6上部署。您可以轻松地将MTAudioProcessingTap添加到您现有的AVPlayer项目,并在您的过程callback函数中将选定的通道样本复制到另一个通道。 这是一个很好的教程,解释基础知识: http : //chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/

这是我迄今为止的代码,主要是从上面的链接复制。

在AVPlayer设置期间,我为audio处理分配callback函数:

MTAudioProcessingTapCallbacks callbacks; callbacks.version = kMTAudioProcessingTapCallbacksVersion_0; callbacks.clientInfo = ( 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 audioInputParam.audioTapProcessor = tap; // Create a new AVAudioMix and assign it to our AVPlayerItem AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; audioMix.inputParameters = @[audioInputParam]; playerItem.audioMix = audioMix; 

这里是audio处理function(实际上只有一个需要的过程):

 #pragma mark Audio Processing void init(MTAudioProcessingTapRef tap, void *clientInfo, void **tapStorageOut) { NSLog(@"Initialising the Audio Tap Processor"); *tapStorageOut = clientInfo; } void finalize(MTAudioProcessingTapRef tap) { NSLog(@"Finalizing the Audio Tap Processor"); } void prepare(MTAudioProcessingTapRef tap, CMItemCount maxFrames, const AudioStreamBasicDescription *processingFormat) { NSLog(@"Preparing the Audio Tap Processor"); } void unprepare(MTAudioProcessingTapRef tap) { NSLog(@"Unpreparing the Audio Tap Processor"); } 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); SIVSViewController* self = (SIVSViewController*) MTAudioProcessingTapGetStorage(tap); if (self.selectedChannel) { int channel = self.selectedChannel; if (channel == 0) { bufferListInOut->mBuffers[1].mData = bufferListInOut->mBuffers[0].mData; } else { bufferListInOut->mBuffers[0].mData = bufferListInOut->mBuffers[1].mData; } } }