NSTimer to smooth out playback position
- by Michael
I have an audio player and I want to show the current time of the the playback. I'm using a custom play class.
The app downloads the mp3 to a file then plays from the file when 5% has been downloaded. I have a progress view update as the file plays and update a label on each call to the progress view. However, this is jerky... sometimes even going backward a digit or two.
I was considering using an NSTimer to smooth things out. I would be fired every second to a method and pass the percentage played figure to the method then update the label.
First, does this seem reasonable?
Second, how do I pass the percentage (a float) over to the target of the timer. Right now I am putting the percent played into a dictionary but this seems less than optimal.
This is what is called update the progress bar:
-(void)updateAudioProgress:(Percentage)percent {
audio = percent;
if (!seekChanging) slider.value = percent;
NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc] init];
[myDictionary setValue:[NSNumber numberWithFloat:percent] forKey:@"myPercent"];
[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(myTimerMethod:)
userInfo:myDictionary
repeats:YES];
[myDictionary release];
}
This is called first after 5 seconds but then updates each time the method is called.
As always, comments and pointers appreciated.