1

How would I go about increasing the progress counter for a UIProgressView while my AVAudioRecorder is recording? I'm not really sure where to increment the progressview...

Code to begin and end recording:

- (IBAction)beginRecording:(id)sender {

        if (player.playing) {
            [player stop];
        }

        AVAudioSession *session = [AVAudioSession sharedInstance];
        [session setActive:YES error:nil];

        // Start recording
        [recorder recordForDuration:8];

        [_recordButton setTitle:@"Recording..." forState:UIControlStateNormal];
}

- (IBAction)endRecording:(id)sender {

    // logic to stop recording
    [recorder stop];

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setActive:NO error:nil];

    [_recordButton setTitle:@"Record" forState:UIControlStateNormal];
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:nil];
    [player setDelegate:self];
    [player play];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Apollo
  • 8,874
  • 32
  • 104
  • 192

1 Answers1

1

you need use NSTimer to read AVAudioRecorder.currentTime and update your UIProgressView.progress .

For Example :

- (void)startRecord
{

    NSTimer *tm = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                                   target:self
                                                 selector:@selector(updateRecordingProgress)
                                                 userInfo:nil
                                                  repeats:YES];
    [tm fire];
}

- (void)updateRecordingProgress
{
    //update your UIProgressView here
    yourProgressView.progress = (recorder.currentTime / 8.0);

}
Kun Wang
  • 81
  • 1
  • 6