Sir, What do you think the error of my Code.. because i cant record a Audio. can you help me in my project? i want to make a simple Recording Project. with three Buttons (PLAY, STOP, RECORD)...by the way i didnt use the nib file. im newbie in Objective-C my approach is purely Programmatically..Thanks in advance more power..
and this is my code in viewDidLoad()
-(void)viewDidLoad
{
[super viewDidLoad];{
playButton.enabled = NO;
stopButton.enabled = NO;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]initWithURL:soundFileURL settings:recordSettings error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
}
else
{
[audioRecorder prepareToRecord];
}
}
-(void) recordButton:(UIButton *)sender
{
if (!audioRecorder.recording)
{
playButton.enabled = NO;
stopButton.enabled = YES;
[audioRecorder record];
NSLog(@"Record");
}
}
-(void)stop:(UIButton *)sender
{
stopButton.enabled = NO;
playButton.enabled = YES;
recordButton.enabled = YES;
if (audioRecorder.recording)
{
[audioRecorder stop];
NSLog(@"Stop");
}
else if (audioPlayer.playing)
{
[audioPlayer stop];
}
}
-(void) playAudio:(UIButton *)sender
{
NSError *error;
if (!audioRecorder.recording)
{
stopButton.enabled = YES;
recordButton.enabled = NO;
NSLog(@"Play");
if (audioPlayer)
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioRecorder.url error:&error];
audioPlayer.delegate = self;
}
if (error)
{ NSLog(@"Error: %@",
[error localizedDescription]);
}
else
[audioPlayer play];
}
}