如何以分钟为单位获得歌曲长度?

how to get song length in minutes?

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

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

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];
 }

这是数学最少的路线。

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