I need to record audio stream with iPhone mic. I am using AVAudioRecorder from this thing.
I initialize AVAR in init:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachePath = [[paths objectAtIndex:0] retain];
NSError *error;
BOOL isDir = NO;
if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error];
}
pathNewFile= [cachePath stringByAppendingPathComponent:@"123.caf"];
NSLog(@"%@",pathNewFile);
NSDictionary *settings=[[NSDictionary alloc]initWithObjectsAndKeys:
[NSNumber numberWithFloat:44100.0f],AVSampleRateKey,
[NSNumber numberWithInt:kAudioFormatAppleLossless],AVFormatIDKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMax],AVEncoderAudioQualityKey, nil];
recorder=[[AVAudioRecorder alloc] initWithURL:[NSURL URLWithString:pathNewFile] settings:settings error:nil];
[recorder prepareToRecord];
And I start recording when user presses the rec-button:
-(void)recButton:(id)sender{
NSLog(@"start rec");
[rootNotesButton setTitle:@"Stop" forState:UIControlStateNormal];
[rootNotesButton removeTarget:self action:@selector(recButton:) forControlEvents:UIControlEventTouchUpInside];
[rootNotesButton addTarget:self action:@selector(stopButton:) forControlEvents:UIControlEventTouchUpInside];
[recorder record];
}
-(void)stopButton:(id)sender{
NSLog(@"stop rec");
[rootNotesButton setTitle:@"Play" forState:UIControlStateNormal];
[rootNotesButton removeTarget:self action:@selector(stopButton:) forControlEvents:UIControlEventTouchUpInside];
[rootNotesButton addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
[recorder stop];
}
-(void)playButton:(id)sender{
NSLog(@"play rec");
[rootNotesButton setTitle:@"Stop" forState:UIControlStateNormal];
[rootNotesButton removeTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
[rootNotesButton addTarget:self action:@selector(stopPButton:) forControlEvents:UIControlEventTouchUpInside];
player=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:pathNewFile] error:nil];
[player play];
}
-(void)stopPButton:(id)sender{
NSLog(@"Stop play");
[rootNotesButton setTitle:@"Play" forState:UIControlStateNormal];
[rootNotesButton removeTarget:self action:@selector(stopPButton:) forControlEvents:UIControlEventTouchUpInside];
[rootNotesButton addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
[player stop];
}
But when I try to run my project in simulator: My debugger stops on string: recorder=[[AVAudioRecorder alloc] initWithURL:[NSURL URLWithString:pathNewFile] settings:settings error:nil]; Without any signal or error.