반응형
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
반응형
'program story' 카테고리의 다른 글
iOS 자산 번들을 만드는 방법은 무엇입니까? (0) | 2021.01.05 |
---|---|
보기를 뒤로 보내는 방법은 무엇입니까? (0) | 2021.01.05 |
각각에 대한 C ++, 벡터 요소에서 가져 오기 (0) | 2021.01.05 |
번들 명령을 찾을 수 없음 Mac (0) | 2021.01.05 |
'automaticallyAdjustsScrollViewInsets'는 iOS 11.0에서 더 이상 사용되지 않습니다. (0) | 2021.01.05 |