现在我正在尝试获取iOS中歌曲的长度。如何限制iOS中的float值
- (NSString *)returnofTotalLength
{
float duration = [[self.player.nowPlayingItem valueForProperty:MPMediaItemPropertyPlaybackDuration] floatValue]/60.0f;
NSString *length = [NSString stringWithFormat:@"%.2f",duration];;
NSString *totalLength = [length stringByReplacingOccurrencesOfString:@"." withString:@":"];
return totalLength;
}
以上代码是歌曲的总长度,如5:90
所示。 您知道5:90
不能为真,因为60
秒是1
分钟。
这应该是6:30
。
所以我要限制1 minute (60 seconds).
该值如何我能做到这一点请大家帮我?
谢谢。
你可以显示它在Objective-C? –
刚编辑我的答案。 –