简体   繁体   English

AVAudioRecorder [记录器记录]总是返回NO

[英]AVAudioRecorder [recorder record] always return NO

I have a problem with recording functionality of my application: 我的应用程序的录制功能有问题:

Recording directory is: /Document/Recordings/ 录制目录为:/ 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");
}

The problem is [aRecorder prepareToRecord] always return TRUE, that will create a record file in system (/Document/Recordings). 问题是[aRecorder prepareToRecord]始终返回TRUE,这将在系统(/ Document / Recordings)中创建一个记录文件。 But [aRecorder record], this method to begin recording, always return FALSE. 但是[aRecorder记录],此方法开始记录,始终返回FALSE。 That will make the record file is 0 byte, can not do anything with it. 那将使记录文件为0字节,无法对其执行任何操作。

I hope anyone have see this problem before and help me. 希望任何人以前都曾遇到过这个问题并能帮助我。 Thanks. 谢谢。

如果AVAudioRecorder之前初始化SimpleAudioEngine ,则可能是问题。因为它可能会被您的AVAudioSession setCategory覆盖。因此,请在您的课程中注释所有[SimpleAudioEngine SharedEngine],它可能会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM