OGeek|极客世界-中国程序员成长平台

标题: ios - 如何以分钟为单位获得歌曲长度? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:52
标题: ios - 如何以分钟为单位获得歌曲长度?

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



Best Answer-推荐答案


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

这是最少的数学路线。

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

关于ios - 如何以分钟为单位获得歌曲长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31509397/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4