如何显示视频的当前时间?我正在使用 Obj-C 进行开发,并且正在使用 QTKit 框架。我想知道如何为QTMovieView不断通知我的函数"刷新当前时间文本字段"。我找到了一个苹果样本,但事实证明很难提取我真正需要的东西。(http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)
创建一个每秒更新一次的 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];
}