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.....

在这个代码中歌曲持续时间进入第二个我需要歌曲持续时间到几分钟怎么可能...thanx

4

3 回答 3

2
 -(NSString *)trackDuration:(NSInteger)duration {
     NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
     return  [formatter stringFromTimeInterval:duration];
 }

这是最少的数学路线。

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

于 2018-04-24T19:08:22.160 回答
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);
于 2015-07-20T06:16:54.230 回答
-1

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

于 2015-07-20T05:38:26.013 回答