Operation could not be completed. AVAudioRecorder iphone SDK
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
Your problem is kAudioFormatMPEGLayer3
Unfortunately you can't encode sound on iPhone in mp3 format. At present time best format for compressed audio is kAudioFormatAppleIMA4. (yes, there is also kAudioFormatMPEG4AAC - even better, but it works only on simulator, but not on device). Note also that there can be problems with decoding of recorded kAudioFormatAppleIMA4 file on other systmes e.g. windows, so simple lpcm format may be more convenient for small files.
精彩评论