displaying music current time & duration from AVFoundation
- by msb
I have a view-based iphone application that has a single play-pause button that plays an mp3 file.
At the time of invoking my doPlayPauseButton() method, I 'd like to show the current time and total duration of this mp3 through the AVAudioPlayer instance I've created, called myAudioPlayer.
I have placed two labels at the UI and i'm trying to assign the currentTime and duration properties to these label when the playing begins but my attempts have failed. Here's my play/pause loop, any help would be appreciated:
-(IBAction) doPlayPauseButton:(UIButton *)theButton {
if(myAudioPlayer.playing) {
[myActivityIndicatorView stopAnimating];
myActivityIndicatorView.hidden = YES;
//I think I need a myAudioPlayer.currentTime call of some sort for my labels.
[myAudioPlayer pause];
[theButton setTitle:@"Play" forState:UIControlStateNormal];
[myTimer invalidate];
}
else {
[myActivityIndicatorView startAnimating];
myActivityIndicatorView.hidden = NO;
myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(doTimer) userInfo:nil repeats:YES];
[myAudioPlayer play];
[theButton setTitle:@"Pause" forState:UIControlStateNormal];