创建一个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], ¤tTime);
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];
}
我犹豫是否使用NSTimer,但我后来认为它是'错误的代码'。但最后,根据你的答案和其他人不是。谢谢。也就是说,我仍然对QTKit感兴趣......(如果可能......) – jlink 2011-05-16 04:52:02
当模数处理double值时,int casts不见了。 int minutes =(int)(currentTime/60)%60; int seconds =(int)currentTime%60; – jlink 2011-05-16 20:46:23