Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialization of AVAudioRecorder with aac

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...!

like image 563
Markus Avatar asked Nov 05 '22 13:11

Markus


1 Answers

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.

like image 100
Shmidt Avatar answered Nov 15 '22 04:11

Shmidt