AVAudioRecorder not working on iPhone 5S

前端 未结 3 524
渐次进展
渐次进展 2020-12-14 21:34

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 sepera

相关标签:
3条回答
  • 2020-12-14 22:10

    It looks like it's actually an interaction between AVNumberOfChannelsKey and AVEncoderBitRateKey. I can't seem to record above 64000Kbps when the # of channels = 1, but when it = 2, I can use 128000...

    0 讨论(0)
  • 2020-12-14 22:15

    I had this same problem - and the answer proved to be related to AVAudioSession. I needed to set the audio session category to PlayAndRecord. Other parts of my application were setting it to Ambient. This post https://stackoverflow.com/a/10287793/1009125 gave me the answer. Hope this helps someone, I lost a Sunday to this one.

    0 讨论(0)
  • 2020-12-14 22:17

    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};
    

    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.

    0 讨论(0)
提交回复
热议问题