此代码有效,但当我移至 iOS 6 时,它停止支持 mp4。
我准备写
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];
然后记录,sto,保存它,当我尝试播放时:
_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);
}
}
我得到和错误:
错误:操作无法完成。(OSStatus 错误 1685348671。)
该代码适用于未压缩格式。压缩的 mp4 适用于装有 iOS 6 的 iPhone 4,也适用于装有 iOS 5.x 的 iphone 4S,但不适用于装有 iOS 6 的 iphone 4S 或 iphone 5。
AVAudioRecorder 录制并写入文件,然后 AVAudioPlayer 出现错误 Error: The operation could not be completed。(OSStatus 错误 1685348671。)。文档指出文件格式已损坏。
有任何想法吗?