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.....
在这段代码中歌曲持续时间进入第二秒我需要几分钟进入歌曲持续时间怎么可能... thanx
最佳答案
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);