Objective c 如何显示视频的当前时间?
如何显示视频的当前时间?我在Obj-C中开发,我在使用QTKit框架。我想知道如何处理我的函数“refreshCurrentTimeTextField”的QTMovieView。我找到了一个苹果样品,但要提取出我真正需要的东西却非常困难。(http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)创建每秒更新一次的NSTimer:Objective c 如何显示视频的当前时间?,objective-c,cocoa,qtkit,Objective C,Cocoa,Qtkit,如何显示视频的当前时间?我在Obj-C中开发,我在使用QTKit框架。我想知道如何处理我的函数“refreshCurrentTimeTextField”的QTMovieView。我找到了一个苹果样品,但要提取出我真正需要的东西却非常困难。(http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)创建每秒更新一次的NSTimer: [NSTimer scheduled
[NSTimer scheduledTimerWithInterval:1.0目标:自选择器:@selector(refreshCurrentTimeTextField)用户信息:无重复:是]
然后创建计时器回调函数,并将时间转换为正确的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做这件事感兴趣。。。(如果可能的话…)当模处理双值时,int类型转换丢失。整数分钟=(整数)(当前时间/60)%60;整数秒=(整数)当前时间%60;