I want to initialize a AVAudioRecorder with a aac file format, but it doesnt work...
Whats wrong with the following code?
soundFilePath = [soundFilePath stringByAppendingPathExtension:@"aac"];
NSURL *url = [NSURL fileURLWithPath:soundFilePath isDirectory:FALSE];
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt: 'aac '] forKey:AVFormatIDKey]; //General Audio Format Settings
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; // "
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey]; // "
[recordSetting setValue:[NSNumber numberWithInt: 32] forKey:AVLinearPCMBitDepthKey]; //Linear PCM Format Settings
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; // "
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVEncoderAudioQualityKey]; //Encoder Settings
[recordSetting setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey]; // "
[recordSetting setValue:[NSNumber numberWithInt:AVAudioQualityLow] forKey:AVSampleRateConverterAudioQualityKey]; //Sample Rate Conversion Settings
_recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:nil];
this allocation just returns nil...
Any help will be appreciated...!
Remove every line about PCM, and change line with formatIDKey
to
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
Btw, it's more proper to use m4a
as an extension, rather than aac
, because aac extension was used for MPEG2 AAC format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With