2012-02-18 19 views
46

これはばかばかしいかもしれませんが、Objective-CのコンソールにCMTime秒をどのように出力できますか?私は単純にタイムスケールで割った値を必要とし、何とかそれをコンソールで見ます。CMTime秒の出力

答えて

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

CMTimeGetSecondsがNaNを返す場合はどうですか? – BUDDAx2

+0

私の推測は、入力は['CMTime'定数の1つです(https://developer.apple.com/library/IOs/documentation/CoreMedia/Reference/CMTime/index.html#//apple_ref/doc/constant_group/Time_Constants)(おそらく 'kCMTimeZero'ではありません)。 'CMTimeShow'を使ってフィールドの内容を調べてみてください。 –

+0

「継続時間> 0」のチェックが機能する – BUDDAx2

12

シンプル:

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

パーフェクトを使用することができますが、魔法のように動作します! – arik

4

あなたは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); 
0
CMTime currentTime = audioPlayer.currentItem.currentTime; 
float videoDurationSeconds = CMTimeGetSeconds(currentTime);