2

How to do to display current time of a video ? I am developing in Obj-C and I am using QTKit framework. I am wondering how to do for that QTMovieView notify continually my function "refreshCurrentTimeTextField". I found an Apple sample but it turned to be quite difficult to extract what I really need. (http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)

4

1 回答 1

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];
}
于 2011-05-16T04:31:16.700 回答