cod*_*yko 13 iphone objective-c avaudiorecorder ios
所以我正在使用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");
}
}
Run Code Online (Sandbox Code Playgroud)
同样,这适用于除5S之外的所有设备.有人知道是什么原因引起的吗?
cod*_*yko 28
做了一些挖掘,我显然找到了解决方案.我只是摆脱了AVEncoderBitRateKey,一切正常.所以现在我的recordSettings字典看起来像这样:
// Setup audio recording
NSDictionary *recordSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVEncoderAudioQualityKey: @(AVAudioQualityLow),
AVNumberOfChannelsKey: @1,
AVSampleRateKey: @22050.0f};
Run Code Online (Sandbox Code Playgroud)
仍然不确定为什么只有iPhone 5S就是这种情况.同样,我已经在运行iOS6和iOS7的所有其他设备上进行了测试,并且旧设置字典在除5S之外的所有设备上都能正常工作.现在我已经删除了AVEncoderBitRateKey和值,它也适用于5S.
| 归档时间: |
|
| 查看次数: |
3434 次 |
| 最近记录: |