我正在使用AVAudioRecorder录制音频,但我正在经历按钮按下和开始录制之间的4秒延迟。AVAudioRecorder记录4秒滞后
这是我的设置代码:
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 16000.0],AVSampleRateKey, [NSNumber numberWithInt: kAudioFormatAppleIMA4],AVFormatIDKey, [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, [NSNumber numberWithInt: AVAudioQualityMax],AVEncoderAudioQualityKey,nil]; NSError *error = nil; audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error]; if (error) { NSLog(@"error: %@", [error localizedDescription]); } else { NSLog(@"prepare to record"); [audioRecorder prepareToRecord]; }
-(void)record {
NSLog(@"Record"); //[audioRecorder prepareToRecord]; if (!audioRecorder.recording) { NSLog(@"Record 2"); [audioRecorder record]; NSLog(@"Record 3"); }
}
记录被称为按下按钮的功能。我知道prepareToRecord是通过'record'隐式调用的,但我想看看它是否会影响延迟。它不是。
这里的控制台日志:
2011-10-18 21:48:06.508 [2949:707] Record
2011-10-18 21:48:06.509 [2949:707] Record 2
2011-10-18 21:48:10.047 [2949:707] Record 3
有大约3.5秒钟,这两点开始录制之前。
这些设置对于iPhone来说太多了吗? (iPhone 4)。我初始化它错了吗?