Operation could not be completed. AVAudioRecorder iphone SDK

Posted by Jonathan on Stack Overflow See other posts from Stack Overflow or by Jonathan
Published on 2010-03-15T20:05:37Z Indexed on 2010/03/15 20:09 UTC
Read the original article Hit count: 645

I am trying to record using the iphones microphone: This is my code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

// the path to write file
NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"testing.mp3"];




NSURL *url = [NSURL fileURLWithPath:appFile isDirectory:NO];

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                          [NSNumber numberWithInt: kAudioFormatMPEGLayer3], AVFormatIDKey,
                          [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                          [NSNumber numberWithInt: AVAudioQualityLow],         AVEncoderAudioQualityKey,
                          nil];

NSError *error;

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

if ([recorder prepareToRecord] == YES){
    [recorder record];
}else {
    int errorCode = CFSwapInt32HostToBig ([error code]); 
    NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode); 

}

NSLog(@"BOOL = %d", (int)recorder.recording);

This is the error I get:

Operation could not be completed. (OSStatus error 1718449215.)

And I can not work out why this doesn't work, as a lot of the code I got from a website.

Jonathan

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk-3.0