iOS AVAudioRecorder [recorder record] always return NO

haisergeant

macrumors newbie
Original poster
Aug 8, 2011
5
0
I have a problem with recording functionality of my application:

Recording directory is: /Document/Recordings/

Code:
[recordingSettings setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordingSettings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordingSettings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
[recordingSettings setValue:[NSNumber numberWithInt:AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];

NSURL *url = [NSURL fileURLWithPath:[[GlobalRecording recordingDirectory] stringByAppendingPathComponent:currentFileName]];
NSError *err = nil;
AVAudioRecorder *aRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordingSettings error:&err];
if( err ){
    NSLog(@"could not create a recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

[aRecorder setDelegate:self];
aRecorder.meteringEnabled = YES;
BOOL temp = [aRecorder prepareToRecord];
if (temp) {
    NSLog(@"Prepare TRUE");
} else {
    NSLog(@"Prepare FALSE");
}
temp = [aRecorder record];
if (temp) {
    NSLog(@"Record TRUE");
} else {
    NSLog(@"Record FALSE");
}
The problem is [aRecorder prepareToRecord] always return TRUE, that will create a record file in system (/Document/Recordings). But [aRecorder record], this method to begin recording, always return FALSE. That will make the record file is 0 byte, can not do anything with it.

I hope anyone have see this problem before and help me. Thanks.
 

RonC

macrumors regular
Oct 18, 2007
108
0
Chicago-area
Some things that jump out at me immediately:

  • Does the path really begin with /? That's the root of the file system and just doesn't sound right. You should probably be using something else. Can you log that path?
  • Do any of the delegate methods get called?
  • Does your device have a microphone? I know it's a silly question, but I thought I'd ask just to make sure.
 

haisergeant

macrumors newbie
Original poster
Aug 8, 2011
5
0
Hi RonC,

- I think the path must begin with "/", that is the absolute path in iphone structure.
The path I log is: /var/mobile/Applications/E43159A0-8706-461C-BC30-4728E3426D32/Documents/Recordings/20111215_171954.caf

- The delegate method not call because it can not recording.
- My device is ipad 2, it has a recording feature.

Thank you very much for your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.