如何在iPhone中从AVAudioPlayer获取持续时间(HH:MM:SS)?

如何在iPhone中从AVAudioPlayer获取持续时间(HH:MM:SS)?,iphone,avaudioplayer,duration,Iphone,Avaudioplayer,Duration,dur目前我正在iPhone应用程序中工作,使用AVAudioPlayer在我的应用程序中播放音频文件,然后从AVAudioPlayer获取持续时间值 我得到的持续时间值是:252.765442 但是我想要HH/MM/ss02:52:76 如何转换这个,请帮助我 提前谢谢 我试过这个: audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:tempFilePath] error:&am

dur目前我正在iPhone应用程序中工作,使用
AVAudioPlayer
在我的应用程序中播放音频文件,然后从
AVAudioPlayer
获取持续时间值

我得到的持续时间值是:252.765442

但是我想要
HH/MM/ss02:52:76

如何转换这个,请帮助我

提前谢谢

我试过这个:

audioPlayer =  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:tempFilePath] error:&err];
    [audioPlayer setDelegate:self];
    [audioPlayer prepareToPlay];

    float duration = (float)audioPlayer.duration;
    NSLog(@"duration:%f",duration);
你也可以试试, 正如@Victor John在Swift中评论的那样,
这就是所谓的填鸭式喂食……持续时间252.765442,然后我试着用这种方式喂你们,但越来越像绳子:05:34:12,它wrong@Minu,则可能必须转换为毫秒。让我检查一下。我想要秒的小时和分钟(音频播放器。持续时间)。没问题。如果你想用objective c的方式,你可以使用它。@Minu,在这里看到了一些注释。我不明白这里发生了什么事。如果你觉得我的答案是正确的(你的问题是以02:52:76的格式回答的,我可以看到只有在我的答案中它是以那种格式存在的),特别是在我得到正确答案之后,你不必担心选择我的答案作为正确答案。无论如何,答案的有用性取决于你自己。这是一种更简单的方法,但在几分钟和几秒钟内都非常有效。非常感谢。它是如此简单和有效。它的Swift代码如下
字符串(格式:“%02d:%02d”、((Int)((audioPlayer?.currentTime)!)/60、((Int)((audioPlayer?.currentTime)!))%60)
NSTimeInterval theTimeInterval = audioPlayer.duration;
 // Get the system calendar
NSCalendar *sysCalendar = [NSCalendar currentCalendar];

// Create the NSDates
NSDate *date1 = [[NSDate alloc] init];
NSDate *date2 = [[NSDate alloc] initWithTimeInterval:theTimeInterval sinceDate:date1];
// Get conversion to hours, minutes, seconds
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *breakdownInfo = [sysCalendar components:unitFlags fromDate:date1  toDate:date2  options:0];
NSLog(@"%02d:%02d:%02d", [breakdownInfo hour], [breakdownInfo minute], [breakdownInfo second]);
[date1 release];
[date2 release];
    // Say you get the duration from AVAudioPlayer *p;
    NSString *dur = [NSString stringWithFormat:@"%02d:%02d", (int)((int)(p.duration)) / 60, (int)((int)(p.duration)) % 60];
    String(format: "%02d:%02d", ((Int)((audioPlayer?.currentTime)!)) / 60, ((Int)((audioPlayer?.currentTime)!)) % 60)