我正在尝试在后台录制。当我使用audiounit技术时,我在背景中看到一个红色条。但是,当我使用AV Foundation框架(AVAudioRecorder)时,我看不到红条。我在所需的背景模式下有“App播放音频”。以下是AudioSession的代码片段
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
与AVAudioRecorder相对应的代码
// ... url, recordSettings initialized properly
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
if([recorder record] == YES)
NSLog(@"Started recording");
与音频单元对应的代码
// Describe audio component
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component
AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc);
// Get audio units
oserr = AudioComponentInstanceNew(inputComponent, &m_audioUnit);
checkStatus(oserr);
// Enable IO for recording
UInt32 flag = 1;
oserr = AudioUnitSetProperty(m_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Input,
1,
&flag,
sizeof(flag));
checkStatus(oserr);
UInt32 enableOutput = 0; // to disable output
AudioUnitElement outputBus = 0;
// Disable output
oserr = AudioUnitSetProperty (
m_audioUnit,
kAudioOutputUnitProperty_EnableIO,
kAudioUnitScope_Output,
outputBus,
&enableOutput,
sizeof (enableOutput)
);
checkStatus(oserr);
oserr = AudioUnitInitialize(m_audioUnit);
oserr = AudioOutputUnitStart(m_audioUnit);
我在iOS 6,iPhone 5上运行它。我不清楚为什么在使用AVAudioRecorder时看不到录制状态栏。有关如何获得它的任何建议?