このコードは機能しましたが、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);
}
}
私はエラーを取得します:
エラー: 操作を完了できませんでした。(OS ステータス エラー 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)。ドキュメントには、ファイル形式が破損していると記載されています。
何か案は?