AVAudioRecorderでこの問題が発生しました。少なくとも私が見ることができる(聞こえない)からです。iOS - AVAudioRecorderでオーディオを記録するとエラーが発生しない
私はARCでiOS 5をターゲットにしています。
私はエラーオブジェクトを設定しましたが、いずれも解雇されなかったので、ここで何か間違っていると思います。録音を開始する時間であるとき
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:currentTrack.trackFileName];
currentTrack.trackFileURL = [NSURL fileURLWithPath:soundFilePath];
NSLog(@"Chemin : %@", currentTrack.trackFileURL.path);
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
currentTrack.trackRecordSettings = recordSetting;
NSError *err = nil;
//[audioSession setDelegate:self];
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
[[AVAudioSession sharedInstance] setActive:YES error:&err];
err = nil;
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
err = nil;
recorder = [[AVAudioRecorder alloc]
initWithURL:currentTrack.trackFileURL
settings:currentTrack.trackRecordSettings
error:&error];
if (err)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Warning"
message: [err localizedDescription]
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"error: %@", [error localizedDescription]);
} else {
[recorder setDelegate:self];
[recorder prepareToRecord];
BOOL audioHWAvailable = [[AVAudioSession sharedInstance]inputIsAvailable ];
if (!audioHWAvailable) {
UIAlertView *cantRecordAlert =
[[UIAlertView alloc] initWithTitle: @"Warning"
message: @"Audio input hardware not available"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[cantRecordAlert show];
return;
}
}
エラーなしが続いてここ
をスローされない:
-(void)startRecordingAudio{
NSLog(@"Start recording");
[[AVAudioSession sharedInstance] setCategory :AVAudioSessionCategoryRecord error:nil];
[recorder record];
}
そして、それがあるときここ
は、一部は私セットアップしたAVAudioRecorderがあります録画を停止する時間:
-(void)stopRecordingAudio{
NSLog(@"Stop recording");
[recorder stop];
NSError *err;
NSData *audioData = [NSData dataWithContentsOfFile:currentTrack.trackFileURL.path options: 0 error:&err];
if(!audioData)
NSLog(@"audio data error: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
NSLog(@"%d", audioData.length);
}
audioDataの長さは常に4096ですか?
が-(void)startPlayingAudio{
[[AVAudioSession sharedInstance] setCategory :AVAudioSessionCategoryPlayback error:nil];
NSLog(@"Start playing");
NSError *error;
if(player == nil){
player = [[AVAudioPlayer alloc] initWithContentsOfURL:currentTrack.trackFileURL
error:&error];
}
player.delegate = self;
if (error)
NSLog(@"Error: %@",
[error localizedDescription]);
else
[player play];
}
私もセットアップデリゲートメソッドを発射しませんでした:
私が右理解していれば、それは録音した音を再生するための時間があるときには、音の約93ミリ秒...最後にです
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
NSLog (@"audioRecorderDidFinishRecording:successfully:");
}
-(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
NSLog(@"Decode Error occurred");
}
-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully: (BOOL)flag
{
NSLog (@"audioRecorderDidFinishRecording:successfully: %d", flag);
}
-(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error
{
NSLog(@"Encode Error occurred");
}
-(void)beginInterruption{
NSLog(@"INTERRUPT");
}
また、私のアプリケーションドキュメントフォルダに.cafファイルが正しく作成されていることがわかりました。
ご協力いただきありがとうございます。今のところ、私は録音された音を聞くことができませんし、ヘッドフォンなしでiPhone 4デバイスを使ってテストします。