program story

CMTime 초 출력

inputbox 2021. 1. 5. 08:04
반응형

CMTime 초 출력


이것은 우스꽝스러워 보일 수 있지만 Objective-C에서 CMTime의 초를 콘솔에 어떻게 출력 할 수 있습니까? 값을 시간 단위로 나눈 다음 어떻게 든 콘솔에서 볼 수 있습니다.


NSLog(@"seconds = %f", CMTimeGetSeconds(cmTime));

단순한:

        NSLog(@"%lld", time.value/time.timescale);

hh:mm:ss형식 으로 변환 하려면 이것을 사용할 수 있습니다.

NSUInteger durationSeconds = (long)CMTimeGetSeconds(audioDuration);
NSUInteger hours = floor(dTotalSeconds / 3600);
NSUInteger minutes = floor(durationSeconds % 3600 / 60);
NSUInteger seconds = floor(durationSeconds % 3600 % 60);
NSString *time = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", hours, minutes, seconds];
NSLog(@"Time|%@", time);

CMTime디버깅 목적으로 콘솔에 a를 인쇄 하려면 CMTimeShow다음을 사용하십시오 .

목표 -C

CMTime time = CMTimeMakeWithSeconds(2.0, 60000); 
CMTimeShow(time);

빠른

var time = CMTimeMakeWithSeconds(2.0, 60000)
CMTimeShow(time)

그것은 인쇄됩니다 value, timescale그리고 계산 seconds:

{120000/6000 = 2.0}

 CMTime currentTime = audioPlayer.currentItem.currentTime;
 float videoDurationSeconds = CMTimeGetSeconds(currentTime);

이 이전의 모든 답변은 NaN 케이스를 처리하지 않습니다.

스위프트 5 :

/// Convert CMTime to TimeInterval
///
/// - Parameter time: CMTime
/// - Returns: TimeInterval
func cmTimeToSeconds(_ time: CMTime) -> TimeInterval? {
    let seconds = CMTimeGetSeconds(time)
    if seconds.isNaN {
        return nil
    }
    return TimeInterval(seconds)
}

참조 URL : https://stackoverflow.com/questions/9345098/cmtime-seconds-output

반응형