2012-02-18 18 views
46

Bu çok saçma görünebilir, ancak CMTime saniye sürelerini Objective-C'deki konsola nasıl verebilirim? Sadece zaman ölçeğine bölünmüş değere ihtiyacım var ve sonra bir şekilde konsolda görüyorum.CMTime saniye çıkışı

cevap

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

CMTimeGetSeconds NaN döndürdüğünde bu durumda nasıl olur? – BUDDAx2

+0

Tahminim, girişin ['CMTime' sabitlerinden] biri olmasıdır (https://developer.apple.com/library/IOs/documentation/CoreMedia/Reference/CMTime/index.html#//apple_ref/doc/constant_group/Time_Constants) (muhtemelen "kCMTimeZero" değil). Alanlarının ne olduğunu görmek için 'CMTimeShow' kullanmayı deneyin. –

+0

"duration> 0 için kontrol et" benim için çalışıyor – BUDDAx2

12

Basit: Eğer hh:mm:ss biçiminde dönüştürmek istiyorsanız

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

Mükemmel kullanabilirsiniz bir cazibe gibi çalışır! – arik

4

o zaman bu

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);