2012-02-18 28 views
46

यह हास्यास्पद प्रतीत हो सकता है, लेकिन मैं उद्देश्य-सी में कंसोल के लिए सीएमटाइम के सेकंड कैसे आउटपुट कर सकता हूं? मुझे बस टाइमकेल द्वारा विभाजित मूल्य की आवश्यकता है और फिर इसे किसी भी तरह कंसोल में देखें।सीएमटाइम सेकंड आउटपुट

उत्तर

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

उस मामले के बारे में जब CMTimeGetSeconds NaN लौटाता है? – BUDDAx2

+0

मेरा अनुमान है कि इनपुट ['सीएमटाइम 'स्थिरांक] में से एक है (https://developer.apple.com/library/IOs/documentation/CoreMedia/Reference/CMTime/index.html#//apple_ref/doc/constant_group/टाइम_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);