2

ビデオの現在の時刻を表示するにはどうすればよいですか?私はObj-Cで開発しており、QTKitフレームワークを使用しています。そのQTMovieViewが私の関数"refreshCurrentTimeTextField"に継続的に通知する方法を知りたいです。Appleのサンプルを見つけましたが、本当に必要なものを抽出するのは非常に困難でした。(http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)

4

1 に答える 1

2

1秒に1回更新する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 に答える