所以我正在使用AVAudioRecorder录制音频,同时使用记录视频的AVCaptureSession(我知道这很奇怪,但对于我的情况,我需要分别记录它们)。
除了iPhone 5S之外,所有设备上一切正常。它可以成功录音,但保存到磁盘上的文件损坏或其他问题。当我在Mac上访问文件系统并尝试使用VLC或Quicktime播放m4a文件时,会出现“无法检测文件格式”的错误。以下是我初始化AVAudioRecorder和录制音频的方法:
// Prepare the audio session
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeVideoRecording error:nil];
// Setup audio recording
NSDictionary *recordSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVEncoderAudioQualityKey: @(AVAudioQualityLow),
AVEncoderBitRateKey: @16,
AVNumberOfChannelsKey: @1,
AVSampleRateKey: @22050.0f};
NSError *audioRecorderError;
NSURL *audioFileURL = [[self.outputFileURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"m4a"];
self.audioRecorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL
settings:recordSettings
error:&audioRecorderError];
self.audioRecorder.delegate = self;
if (audioRecorderError) {
CCLog(@"Error while initializing the audio recorder... Skipping sound recording!");
}
else {
if (![self.audioRecorder prepareToRecord]) {
CCLog(@"Error preparing to record");
}
if (![self.audioRecorder record]) {
CCLog(@"Error recording");
}
}
同样的代码在除了iPhone 5S以外的所有设备上都能正常工作。有人知道可能是什么原因导致这个问题吗?