displaying music current time & duration from AVFoundation
Posted
by msb
on Stack Overflow
See other posts from Stack Overflow
or by msb
Published on 2010-05-23T06:32:11Z
Indexed on
2010/05/23
6:40 UTC
Read the original article
Hit count: 406
iphone
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];
© Stack Overflow or respective owner