2012-02-18 27 views
46

Điều này có vẻ vô lý, nhưng làm thế nào tôi có thể xuất các giây của CMTime sang bàn điều khiển trong Mục tiêu-C? Tôi chỉ cần giá trị chia cho thời gian và sau đó bằng cách nào đó nhìn thấy nó trong giao diện điều khiển.Đầu ra giây trong CMTime

Trả lời

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

thế nào về trường hợp đó khi CMTimeGetSeconds trả về NaN? – BUDDAx2

+0

Đoán của tôi là đầu vào là một trong các hằng số ['CMTime'] (https://developer.apple.com/library/IOs/documentation/CoreMedia/Reference/CMTime/index.html#//apple_ref/doc/constant_group/Time_Constants) (có thể không phải 'kCMTimeZero'). Hãy thử sử dụng 'CMTimeShow' để xem các trường của nó là gì. –

+0

kiểm tra "duration> 0" hoạt động cho tôi – BUDDAx2

12

đơn giản:

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

Perfect, hoạt động như một nét duyên dáng! – arik

4

Nếu bạn muốn chuyển đổi định dạng hh:mm:ss sau đó bạn có thể sử dụng

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