Ios 如何在几分钟内获得歌曲长度?

Ios 如何在几分钟内获得歌曲长度?,ios,objective-c,audio,duration,minute,Ios,Objective C,Audio,Duration,Minute,在这段代码中歌曲持续时间进入秒我需要歌曲持续时间进入分钟如何可能。。。thanx将秒(int)转换为分钟(double) 这是最少的数学途径 对于SpotifySDK,我必须将持续时间除以1000。算数。将秒转换为分钟!不工作。。不要把厘米时间转换成整数,把秒(浮点数)转换成分钟(浮点数)我不能把厘米时间转换成整数 assetURL = [item valueForProperty: MPMediaItemPropertyAssetURL]; NSLog(@"%@", assetURL); //

在这段代码中歌曲持续时间进入秒我需要歌曲持续时间进入分钟如何可能。。。thanx

将秒(int)转换为分钟(double)

这是最少的数学途径


对于SpotifySDK,我必须将持续时间除以1000。算数。

将秒转换为分钟!不工作。。不要把厘米时间转换成整数,把秒(浮点数)转换成分钟(浮点数)我不能把厘米时间转换成整数
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.....
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);
 -(NSString *)trackDuration:(NSInteger)duration {
     NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
     return  [formatter stringFromTimeInterval:duration];
 }