1

我将如何UIProgressView在我的 AVAudioRecorder 录制时增加进度计数器?我不确定在哪里增加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];
}
4

1 回答 1

1

您需要使用 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);

}
于 2013-11-15T07:04:11.477 回答