Xcode 如何使用AVAudioPlayer更新音频播放时的播放时间

Xcode 如何使用AVAudioPlayer更新音频播放时的播放时间,xcode,Xcode,我想在标签上显示音频播放时的播放时间/总持续时间。我见过AVAudioPlayerDelegate方法,但我找不到这种方法,它会在播放后每秒钟通知它一次。我是这样做的: -(IBAction)playAudio{ NSBundle *bundle = [NSBundle mainBundle]; NSString *audioPath = [bundle pathForResource:@"PhirMohobat" ofType:@"mp3"]; NSURL *audioUrl = [NSUR

我想在标签上显示音频播放时的播放时间/总持续时间。我见过AVAudioPlayerDelegate方法,但我找不到这种方法,它会在播放后每秒钟通知它一次。我是这样做的:

-(IBAction)playAudio{

NSBundle *bundle = [NSBundle mainBundle];
NSString *audioPath = [bundle pathForResource:@"PhirMohobat" ofType:@"mp3"];
NSURL *audioUrl = [NSURL fileURLWithPath:audioPath];


player = [[AVAudioPlayer alloc]initWithContentsOfURL:audioUrl error:NULL]; 
player.delegate = self;

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
[player play];

}

-(void)updateTime
{

float minutes = floor(player.currentTime/60);
float seconds = player.currentTime - (minutes * 60);

float duration_minutes = floor(player.duration/60);
float duration_seconds = player.duration - (duration_minutes * 60);

NSString *timeInfoString = [[NSString alloc] 
                            initWithFormat:@"%0.0f.%0.0f / %0.0f.%0.0f",
                            minutes, seconds, 
                            duration_minutes, duration_seconds];


timerLabel.text = timeInfoString;
[timeInfoString release];
}


在AVAudioPlayer或xcode支持的任何其他音频播放器中是否有任何隐式委托方法来执行此操作?

AVAudioPlayer有一个名为currentTime的属性,因此,您可以在一定的时间间隔内使用NSTimer询问此属性的实际值,然后根据此值进行更新,无论您需要什么。

谢谢您的回答,但我很早就尝试过,并且对新方法感兴趣。我想要一个显式回调或任何其他不使用计时器的库来提供此属性