我的应用程序录制功能存在问题:
录制目录是:/ Document / Recordings /
[recordingSettings setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordingSettings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordingSettings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[recordingSettings setValue:[NSNumber numberWithInt:AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];
NSURL *url = [NSURL fileURLWithPath:[[GlobalRecording recordingDirectory] stringByAppendingPathComponent:currentFileName]];
NSError *err = nil;
AVAudioRecorder *aRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordingSettings error:&err];
if( err ){
NSLog(@"could not create a recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[aRecorder setDelegate:self];
aRecorder.meteringEnabled = YES;
BOOL temp = [aRecorder prepareToRecord];
if (temp) {
NSLog(@"Prepare TRUE");
} else {
NSLog(@"Prepare FALSE");
}
temp = [aRecorder record];
if (temp) {
NSLog(@"Record TRUE");
} else {
NSLog(@"Record FALSE");
}
问题是[aRecorder prepareToRecord]总是返回TRUE,这将在系统(/ Document / Recordings)中创建一个记录文件。但是[aRecorder record],这种开始录制的方法总是返回FALSE。这将使记录文件为0字节,无法用它做任何事情。
我希望以前有人能看到这个问题并帮助我。感谢。
答案 0 :(得分:0)
如果您在AVAudioRecorder之前初始化 SimpleAudioEngine ,则会出现问题。因为它可能会覆盖您的 AVAudioSession setCategory 。所以在您的班级中注释所有[SimpleAudioEngine SharedEngine],它可能有效。:)