self.title = [NSStringstringWithFormat:@"%@", [selfformatTime:self.recorder.currentTime]];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
// Prepare UI for recording
self.title = nil;
meter1.hidden = NO;
meter2.hidden = NO;
{
// Return to play and record session
NSError *error;
if (![[AVAudioSessionsharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecorderror:&error])
{
NSLog(@"Error: %@", [error localizedDescription]);
return;
}
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Record", @selector(record));
}
// Delete the current recording
[ModalAlertsay:@"Deleting recording"];
//[self.recorder deleteRecording]; <-- too flaky to use
NSError *error;
if (![[NSFileManagerdefaultManager] removeItemAtPath:[self.recorder.urlpath] error:&error])
NSLog(@"Error: %@", [error localizedDescription]);
// Release the player
[player release];
}
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
// Stop monitoring levels, time
[timerinvalidate];
meter1.progress = 0.0f;
meter1.hidden = YES;
meter2.progress = 0.0f;
meter2.hidden = YES;
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = nil;
[ModalAlertsay:@"File saved to %@", [[self.recorder.urlpath] lastPathComponent]];
self.title = @"Playing back recording...";
// Start playback
AVAudioPlayer *player = [[AVAudioPlayeralloc] initWithContentsOfURL:self.recorder.urlerror:nil];
player.delegate = self;
// Change audio session for playback
NSError *error;
if (![[AVAudioSessionsharedInstance] setCategory:AVAudioSessionCategoryPlaybackerror:&error])
{
NSLog(@"Error: %@", [error localizedDescription]);
return;
}
[player play];
}
- (void) stopRecording
{
// This causes the didFinishRecording delegate method to fire
[self.recorderstop];
}
- (void) continueRecording
{
// resume from a paused recording
[self.recorderrecord];
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Done", @selector(stopRecording));