I’m not sure why this isn’t working. I create an AVAudioRecorder for a file in the documents directory. There are no errors.
When I later call [audioRecorder record], the return value is NO on the iDevice (iPod touch 4G, 5.0.1), but on the iPhone simulator 5.0 it works (and playback works also). I have tried recording to a file in NSTemporaryDirectory() instead of docDir… and also various permutations of settings and formats and file endings. Some combinations work on the simulator and some don’t --some even record but play back incorrectly-- but I haven’t gotten anything to work on the device yet.
Does anyone have a suggestion or see something wrong?
Could someone post some working (on a device) initialization code for an AVAudioRecorder?
Is there a list anywhere of which settings for AVAudioRecorder will work with which devices/iOS-version?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDir = [paths objectAtIndex:0]; NSString *recordPath = [docDir stringByAppendingString:@"/recording.caf"]; NSURL *recordURL = [NSURL fileURLWithPath:recordPath]; NSDictionary *settingsDict = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, [NSNumber numberWithFloat:16000.0], AVSampleRateKey, [NSNumber numberWithInt:1], AVNumberOfChannelsKey, [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey, [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey, [NSNumber numberWithBool:NO], AVLinearPCMIsFloatKey, nil]; NSError *error; audioRecorder = [[AVAudioRecorder alloc] initWithURL:recordURL settings:settingsDict error:&error];