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
答案 0 :(得分:2)
-(NSString *)trackDuration:(NSInteger)duration {
NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
return [formatter stringFromTimeInterval:duration];
}
这是最不数学的路线。
对于SpotifySDK,我必须将持续时间除以1000.去图。
答案 1 :(得分: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);
答案 2 :(得分:-1)
将秒数(int)转换为分钟(双倍)。