質問
これはばかげているように見えるかもしれませんが、CMTIMEの秒をObjective-Cのコンソールに出力するにはどうすればよいですか?値をタイムスケールで分割して、コンソールで何らかの形で表示する必要があります。
解決
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
デバッグのためのコンソールに使用します CMTimeShow
:
Objective-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ケースを処理しません:
SWIFT 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)
}
所属していません StackOverflow