我有一个实时应用程序,估计有 15% 的用户报告说记录功能不起作用。这在我们的测试设备上没有发生,但报告显示问题是 prepareToRecord 返回 NO。我很难找到 AAC 格式的示例设置。我的任何设置都关闭了吗?应用需要 iOS5 并使用 ARC。
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityHigh], AVSampleRateConverterAudioQualityKey,
[NSNumber numberWithInt:128000], AVEncoderBitRateKey,
[NSNumber numberWithInt:16], AVEncoderBitDepthHintKey,
nil];
NSString *fileName = [NSString stringWithFormat:@"%@%@.caf", verseGUID, bRecordingReference ? @"_ref" : @""];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[Utilities sharedInstance] documentsDirectoryPath], fileName]];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
if([audioRecorder prepareToRecord]){
[audioRecorder record];
}else{
int errorCode = CFSwapInt32HostToBig([error code]);
NSLog(@"Error: %@ [%4.4s])", [error localizedDescription], (char*)&errorCode);
}