【发布时间】:2013-03-20 13:31:25
【问题描述】:
此代码有效,但当我迁移到 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];
然后录制、存储、保存以及当我尝试播放时:
_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。)。 文档指出文件格式已损坏。
有什么想法吗?
【问题讨论】:
-
我也有同样的问题。它完成了录制,但文件无法播放。有什么意见吗?
标签: iphone ios objective-c avaudioplayer avaudiorecorder