2011-05-15 7 views
2

비디오의 현재 시간을 표시하려면 어떻게해야합니까? Obj-C에서 개발 중이며 QTKit 프레임 워크를 사용하고 있습니다. 해당 QTMovieView 내 함수 "refreshCurrentTimeTextField"지속적으로 알리는 방법을 궁금합니다. Apple 샘플을 찾았지만 정말 필요한 것을 추출하기가 어려웠습니다. (http://developer.apple.com/library/mac/#samplecode/QTKitMovieShuffler/Introduction/Intro.html)비디오의 현재 시간을 표시하는 방법은 무엇입니까?

답변

2

매초마다 업데이트하는 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]; 
} 
+0

나는 NSTimer를 사용하기를 망설 였지만 '나쁜 코드'라고 생각했습니다. 그러나 마침내 당신의 대답과 다른 사람들에 따르면 그것이 아닙니다. 감사. 그렇다면 여전히 QTKit을 사용하여 흥미를 느낍니다. (가능한 경우 ...) – jlink

+0

모듈러스가 double 값을 처리 할 때 int 캐스트가 누락되었습니다. int 분 = (int) (currentTime/60) % 60; int 초 = (int) currentTime % 60; – jlink

관련 문제