This code worked, but when I moved to iOS 6 it stopped supporting mp4.
I prepare write
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"Temp.mp4"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 32000], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
nil];
NSError *error = nil;
self.audioRecorder = nil;
AVAudioRecorder *audioRecorderBuffer = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
self.audioRecorder = audioRecorderBuffer;
self.audioRecorder.delegate = self;
if (error)
NSLog(@"error: %@", [error localizedDescription]);
else
[self.audioRecorder prepareToRecord];
then record, sto, save it and when I try to play:
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:_audioURL error:&error];
_audioPlayer.delegate = self;
if (error)
NSLog(@"Error: %@", [error localizedDescription]);
else {
[_audioPlayer prepareToPlay];
if (![_audioPlayer play]) {
NSLog(@"Play Error: %@", error);
}
}
I get and error:
Error: The operation couldn’t be completed. (OSStatus error 1685348671.)
The code works on uncompressed format. Compressed mp4 works on iPhone 4 with iOS 6, worked also on iphone 4S with iOS 5.x, but does not work on iphone 4S nor iphone 5 with iOS 6.
AVAudioRecorder records and writes the file, then AVAudioPlayer has error Error: The operation couldn’t be completed. (OSStatus error 1685348671.). Documentation states that file format is corrupted.
Any ideas?