AVAudioRecorder in iOS 8 does not handle kAudioFormatMPEG4AAC

旧时模样 提交于 2019-12-23 10:00:53

问题


My code worked fine until iOS 8 kAudioFormatMPEG4AAC but now it creates an empty file. No errors are reported. When I changed it to kAudioFormatLinearPCM it works. This is my code:

recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
    [NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey,
    [NSNumber numberWithInt:16], AVEncoderBitRateKey,
    [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
    [NSNumber numberWithFloat:32000.0], AVSampleRateKey,
    nil];

回答1:


Please remove AVEncoderBitRateKey key from your settings dictionary and it will work on iOS8 with kAudioFormatMPEG4AAC.

It could be a specific correlation between AVEncoderBitRateKey and AVNumberOfChannelsKey. But I didn't play with parameters but used default bitrate value to get working recorder.




回答2:


That bitrate looks suspiciously low, even for kAudioFormatMPEG4AAC (16 bytes per second), maybe try 16000 or 64000 or more.

p.s. try the new Objective-C literals for your NSDictionarys, NSArrays and NSNumbers, I think they're an improvement:

recordSettings = @{
    AVEncoderAudioQualityKey : AVAudioQualityMin,
    AVFormatIDKey : @(kAudioFormatLinearPCM),
    AVEncoderBitRateKey : @16000,
    AVNumberOfChannelsKey : @1,
    AVSampleRateKey : @32000
}; 


来源:https://stackoverflow.com/questions/27178618/avaudiorecorder-in-ios-8-does-not-handle-kaudioformatmpeg4aac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!