AVAudioRecorder不支持iPhone 5S [英] AVAudioRecorder not working on iPhone 5S

查看:95
本文介绍了AVAudioRecorder不支持iPhone 5S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用AVAudioRecorder在录制视频的AVCaptureSession旁边录制音频(我知道这很奇怪,但对于我的情况,我需要单独录制它们。)

So I'm using an AVAudioRecorder to record audio alongside an AVCaptureSession that is recording video (I know this is odd, but for my situation I need to record them seperately).

除了我的iPhone 5S之外,所有设备上的一切正常。它记录没有错误,但保存到磁盘的文件已损坏或其他。当我在我的Mac上访问文件系统并尝试使用VLC或Quicktime播放m4a文件时,我得到无法检测到文件的格式错误。以下是我初始化AVAudioRecorder和录制音频的方法:

Everything works fine on every device, except for my iPhone 5S. It records without error, but the file that is saved to disk is corrupted or something. When I access the file system on my mac and try and play the m4a file with VLC or Quicktime, I get a "format of the file cannot be detected" error. Here is how I am initializing my AVAudioRecorder and recording my audio:

// 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");
    }
}

同样,这适用于5S以外的所有设备。有人知道造成这种情况的原因吗?

Again, this works on all devices aside from the 5S. Anyone know what could be causing this?

推荐答案

进行了一些挖掘,我显然找到了解决方案。我只是摆脱了AVEncoderBitRateKey,一切正常。所以现在我的recordSettings字典看起来像这样:

Did some more digging and I apparently found the solution. I simply got rid of AVEncoderBitRateKey and everything works fine. So now my recordSettings dictionary looks like this:

// Setup audio recording
NSDictionary *recordSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC),
                                  AVEncoderAudioQualityKey: @(AVAudioQualityLow),
                                  AVNumberOfChannelsKey: @1,
                                  AVSampleRateKey: @22050.0f};

仍然不确定为什么只有iPhone 5S就是这种情况。同样,我已经在运行iOS6和iOS7的所有其他设备上进行了测试,并且旧设置字典在除5S之外的所有设备上都能正常工作。现在我已经删除了AVEncoderBitRateKey和值,它也适用于5S。

Still not sure why this would be the case only on an iPhone 5S. Again, I've tested on all other devices running iOS6 and iOS7, and the old settings dictionary works fine on everything except for the 5S. Now that I've removed the AVEncoderBitRateKey and value, it also works on the 5S.

这篇关于AVAudioRecorder不支持iPhone 5S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆