AVAudioRecorder가 나에게 적합하지 않아서이 문제가 발생했습니다.iOS - AVAudioRecorder가있는 오디오 녹음에 오류가 발생하지 않습니다.
ARC로 iOS 5를 타겟팅하고 있습니다.
오류 개체를 설정했지만 그 중 아무 것도 해고 당하지 않으므로 여기에 잘못된 것이 있습니다. 여기
내가 설정에게 AVAudioRecorder 있던 일부입니다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];
}
을 녹화를 중지 할 시간 :
-(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 장치를 사용하여 테스트합니다.