AVAudioRecorder不会在OS X Mavericks上录制

时间:2015-07-10 13:28:36

标签: cocoa osx-mavericks avaudiorecorder

在我的可可应用中,我尝试从内置麦克风录制声音。我正在使用AVAudioRecorder类来实现此目的。在下面的代码中,我设置了AVAudioRecorder实例。

- (void)setupAudioRecorder {

    NSMutableDictionary *recordSettings = [NSMutableDictionary dictionary];

    recordSettings[AVFormatIDKey] = @(kAudioFormatLinearPCM);
    recordSettings[AVSampleRateKey] = @(16000.0);
    recordSettings[AVNumberOfChannelsKey] = @(1);
    recordSettings[AVLinearPCMBitDepthKey] = @(16);
    recordSettings[AVLinearPCMIsBigEndianKey] = @(NO);
    recordSettings[AVLinearPCMIsFloatKey] = @(NO);

    recordSettings[AVEncoderBitRateStrategyKey] = AVAudioBitRateStrategy_Variable;
    recordSettings[AVEncoderAudioQualityForVBRKey] = @(AVAudioQualityMedium);
    recordSettings[AVSampleRateConverterAlgorithmKey] = AVSampleRateConverterAlgorithm_Mastering;

    recordSettings[AVSampleRateConverterAudioQualityKey] = @(AVAudioQualityMedium);

    NSString *file = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
                   objectAtIndex:0]
                  stringByAppendingPathComponent:@".recorder_voice.caf"];

    NSFileManager *fm = [NSFileManager defaultManager];

    if ([fm fileExistsAtPath:file])
        [fm removeItemAtPath:file error:nil];

    NSURL *url = [NSURL fileURLWithPath:file];
    NSError *err = nil;

    self.recorder.delegate = nil;
        self.recorder = [[AVAudioRecorder alloc] initWithURL:url
                                            settings:recordSettings
                                               error:&err];
    if(!self.recorder){
    // show error
    }

    [self.recorder setDelegate:self];
    [self.recorder prepareToRecord];

    self.recorder.meteringEnabled = YES;
}

在优胜美地,一切正常,但在小牛队,我已经沉默了。执行 [self.recorder prepareToRecord]; 时,系统日志显示错误:

AQMEIO.cpp:377 _FindIOUnit:错误-66680。

这是什么意思,我该如何解决?

1 个答案:

答案 0 :(得分:1)

最后我找到了答案。原因是在沙箱项目设置中。我没有检查Target中的麦克风盒 - >能力 - > App Sanbox。约塞米蒂忽略了这个问题,但Maverics没有。