【发布时间】:2012-07-05 15:35:57
【问题描述】:
我有一个实时应用,估计有 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);
}
【问题讨论】:
-
您是否在当前支持 iOS 5 的所有设备上测试过此应用程序?也许这个问题与硬件有关?
-
我们已经在 iPhone 4s、iPod Touch 第 4 代和 iPhone 3GS 上报告了这个问题,但它不会影响这些相同设备上的其他用户。我们已经在 iPhone 4s、iPhone 4、iPod Touch 第 4 代和 iPad 1 上进行了测试,但未能重现该问题。
-
这会在 sim 卡中崩溃。
-
我的理解是您应该只在设备上进行测试,因为它们使用完全不同的音频硬件。我还看到了一些关于使用 iOS5 在 Sim 中录制和播放音频问题的报告,如下所述:stackoverflow.com/questions/6906930/… 但是,如果您看到您认为可能导致模拟器和设备出现问题的特定设置,请告诉我。
标签: ios ios5 avaudioplayer avaudiorecorder avaudiosession