首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在记录时记录时间

在记录时记录时间
EN

Stack Overflow用户
提问于 2011-02-24 16:17:40
回答 2查看 6.7K关注 0票数 4

我有一个可以录音的AVAudioRecorder。我还有一个标签。我想每秒更新标签上的文字,以显示录制时间。我该怎么做呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-24 16:20:58

您可以使用AVAudioRecorder (audioRecorder.currentTime)的currentTime属性来获取自录制开始以来的NSTimeInterval时间,您可以使用该时间显示在您的标签上。

票数 7
EN

Stack Overflow用户

发布于 2012-12-14 14:30:48

如下所示:

代码语言:javascript
复制
  - (IBAction)startStopRecording:(id)sender 
    {
           //If the app is note recording, we want to start recording, and make the record button say "STOP"
        if(!self.isRecording)
        {
            self.isRecording = YES;  //this is the bool value to store that recorder recording
            [self.recordButton setTitle:@"STOP" forState:UIControlStateNormal];

            recorder = [[AVAudioRecorder alloc] initWithURL:recordedFile settings:nil error:nil];
            [recorder prepareToRecord];
            [recorder record];

            myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];  //this is nstimer to initiate update method
        }

        else
        {
            self.isRecording = NO;
            [self.recordButton setTitle:@"REC" forState:UIControlStateNormal];

            [recorder stop];
            recorder = nil;    
            [myTimer invalidate];
        }

    }

- (void)updateSlider {
    // Update the slider about the music time
    if([recorder isRecording])
    {

        float minutes = floor(recorder.currentTime/60);
        float seconds = recorder.currentTime - (minutes * 60);

        NSString *time = [[NSString alloc] 
                                    initWithFormat:@"%0.0f.%0.0f",
                                    minutes, seconds];
        recordTimeLabel.text = time;
    }
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5102011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档