如何显示视频的当前时间?

时间:2011-05-15 21:13:43

标签: objective-c cocoa qtkit

如何显示视频的当前时间?我在Obj-C开发,我正在使用QTKit框架。我想知道如何为QTMovieView持续通知我的函数“refreshCurrentTimeTextField”。我发现了一个Apple样本,但很难提取出我真正需要的内容。 (http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)

1 个答案:

答案 0 :(得分:2)

创建一个每秒更新一次的NSTimer:

[NSTimer scheduledTimerWithInterval:1.0 target:self selector:@selector(refreshCurrentTimeTextField) userInfo:nil repeats:YES]

然后创建您的计时器回调函数并将时间转换为正确的HH:MM:SS标签:

-(void)refreshCurrentTimeTextField {
    NSTimeInterval currentTime; 
    QTMovie *movie = [movieView movie];
    QTGetTimeInterval([movie currentTime], &currentTime);

    int hours = currentTime/3600;
    int minutes = (currentTime/60) % 60;
    int seconds = currentTime % 60;

    NSString *timeLabel;
    if(hours > 0) {
        timeLabel = [NSString stringWithFormat:@"%02i:%02i:%02i", hours, minutes, seconds];
    } else {
        timeLabel = [NSString stringWithFormat:@"%02i:%02i", minutes, seconds];
    }
    [yourTextField setStringValue:timeLabel];
}