AVAudioRecorder in iOS 8 does not handle kAudioFormatMPEG4AAC

My code worked fine until iOS 8 kAudioFormatMPEG4AAC , but now it creates an empty file. No errors 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]; 
+5
source share
2 answers

Remove the AVEncoderBitRateKey key from your settings dictionary and it will work on iOS8 with kAudioFormatMPEG4AAC .

This may be a specific correlation between AVEncoderBitRateKey and AVNumberOfChannelsKey . But I did not play with the parameters, but used the default bitrate value to get a working recorder.

+3
source

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

ps try the new Objective-C literals for your NSDictionarys , NSArrays and NSNumbers , I think they are improving:

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

Source: https://habr.com/ru/post/1207850/


All Articles