avaudiorecorder正在录制时增加uiprogressview

时间:2013-11-15 05:36:50

标签: ios objective-c avaudiorecorder uiprogressview

在我的AVAudioRecorder正在录制时,如何增加UIProgressView的进度计数器?我不确定在哪里增加progressview ...

开始和结束录制的代码:

- (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];
}

1 个答案:

答案 0 :(得分:0)

您需要使用NSTimer来读取AVAudioRecorder.currentTime并更新您的UIProgressView.progress。

例如:

- (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);

}