assetURL = [item valueForProperty: MPMediaItemPropertyAssetURL];
NSLog(@"%@", assetURL); // asset url declares the song url and song path
AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil]; // declare the audio asset url
CMTime audioDuration = audioAsset.duration; // get duration in cm time
double audioDurationSeconds = CMTimeGetSeconds(audioDuration); // convert audio duration in double
但这是一个问题,因为我只能以秒为单位获得音频持续时间,但是我需要“MM:SS”格式作为歌曲持续时间。
请帮我。提前致谢。
最佳答案
NSUInteger audioDurationSeconds = (long)CMTimeGetSeconds(audioDuration);
NSUInteger minutes = floor(audioDurationSeconds % 3600 / 60);
NSUInteger seconds = floor(audioDurationSeconds % 3600 % 60);
NSString *time = [NSString stringWithFormat:@"%02ld:%02ld", minutes, seconds];
关于ios - 如何获得像 “mm:ss”格式的歌曲的实际持续时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31531590/