創建一個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