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];
}
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.