AVAudioRecorder - correct MPEG4 AAC recording settings

I have a live application, about 15% of users report that the recording function does not work. This does not happen on our test devices, but reports show that the problem is that prepareToRecord returns NO. I could not find sample settings for the AAC format. Are any of my settings turned off? The app requires iOS5 and uses ARC.

AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey, [NSNumber numberWithFloat:44100.0], AVSampleRateKey, [NSNumber numberWithInt:1], AVNumberOfChannelsKey, [NSNumber numberWithInt:AVAudioQualityHigh], AVSampleRateConverterAudioQualityKey, [NSNumber numberWithInt:128000], AVEncoderBitRateKey, [NSNumber numberWithInt:16], AVEncoderBitDepthHintKey, nil]; NSString *fileName = [NSString stringWithFormat:@"%@%@.caf", verseGUID, bRecordingReference ? @"_ref" : @""]; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[Utilities sharedInstance] documentsDirectoryPath], fileName]]; NSError *error = nil; audioRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error]; if([audioRecorder prepareToRecord]){ [audioRecorder record]; }else{ int errorCode = CFSwapInt32HostToBig([error code]); NSLog(@"Error: %@ [%4.4s])", [error localizedDescription], (char*)&errorCode); } 
+7
source share
3 answers

there can be many things not related to recording settings.

the real question that you want to answer seems to be: what could cause the recording not to happen?

audioRecorder may be nil or audioRecorder prepareToPlay may return NO. the first seems more likely.

The URL passed to initWithURL may be garbled: - Have you tested playing with the values โ€‹โ€‹verseGUID, bRecordReference? your devices may never have a bad verseGUID, but devices that don't have a record have a null / empty verseGUID. this may cause the file name to simply be ".caf".

you seem to have your own class method [Utilities sharedInstance]. can this work for some reason on your devices, but not on faulty devices? If so, you can request an entry in the top-level directory when you did not want it.

can you get the testers that you have on the beta list? register for something like TestFlight or the Hockey Kit, ask one or more non-record users to register, and then download the beta version of your application using the diagnostics that put the dialog on the screen with the resulting โ€œerrorโ€. this may be the most obvious. I use testflightapp.com just because it was the first I tried, it was pretty easy to manage for me and pretty painless for my beta testers.

+3
source

Try these settings that I used to record the MPEG 4 AAC format ... Its working well ..

 NSString *tempDir = NSTemporaryDirectory(); NSString *soundFilePath = [tempDir stringByAppendingPathComponent:@"sound.m4a"]; NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath]; NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey, [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey, [NSNumber numberWithInt: 1], AVNumberOfChannelsKey, [NSNumber numberWithFloat:8000.0], AVSampleRateKey, nil]; 
+2
source

I apologize for the fact that this is a little regarding, but I had a very similar problem with the fact that many users could not record, which, in my opinion, was connected with the sound settings.

However, it turned out to me that they refused access to the microphone. This meant that prepareToRecord working (and truncated the file), and record reported that it was working, but actually did not write anything.

And I used this when I want to write:

 AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in if granted { // can record - create AVAudioRecorder here } else { // can't record - update UI (or react accordingly) } }) 

Hope this helps someone if they run into a similar problem.

0
source

All Articles