2015-07-20 42 views
2
assetURL = [item valueForProperty: MPMediaItemPropertyAssetURL]; 
NSLog(@"%@", assetURL); // get song url 
AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil]; // add song url into AVURLasset 
CMTime audioDuration = audioAsset.duration; //get duration in second 
int audioDurationSeconds = CMTimeGetSeconds(audioDuration); // get song duration in seconds..... 
在此代碼的歌曲時長進入第二,我需要的歌曲時長以分鐘計算它是如何可能

...感謝名單如何在幾分鐘內獲得歌曲長度?

+1

將秒轉換爲分鐘! http://stackoverflow.com/questions/15122883/ios-format-string-into-minutes-and-seconds –

+0

不工作..不把cm時間轉換爲int和浮點數 –

回答

1
CMTime audioDuration = audioAsset.duration; 
NSUInteger totalSeconds = CMTimeGetSeconds(audioDuration); 
NSUInteger hours = floor(totalSeconds/3600); 
NSUInteger minutes = floor(totalSeconds % 3600/60); 
NSUInteger seconds = floor(totalSeconds % 3600 % 60); 

NSLog(@"hours = %i, minutes = %02i, seconds = %02i",hours,minutes,seconds); 
+0

謝謝我已經嘗試過... –

0

秒轉換(int)以分鐘(雙)。

+0

秒(浮點數)到分鐘數(浮點數) –

+0

i不能將釐米時間轉換爲整數 –

+0

感謝您的建議Keyur Akbari –

相關問題