Omitted some things here and there, but it's enough to plug in.
// .h
IBOutlet UISlider *progressSlider;
NSTimer *progressTimer;
@property (nonatomic, retain) UISlider *progressSlider;
@property (nonatomic, retain) NSTimer *progressTimer;
- (void)updateSlider;
- (void)resetTimer:(NSTimer *)timer;
// .m
// synthesize variables
- (void)handleNowPlayingItemChanged:(id)notification {
NSNumber *duration = [item valueForProperty:MPMediaItemPropertyPlaybackDuration];
float totalTime = [duration floatValue];
progressSlider.maximumValue = totalTime;
}
- (void)updateSlider {
[progressSlider setValue:musicPlayer.currentPlaybackTime animated:YES];
}
- (void)resetTimer:(NSTimer *)timer {
[progressTimer invalidate];
progressTimer = nil;
progressTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self
selector:@selector(updateSlider)
userInfo:nil repeats:YES];
}
// init and release methods (together at the bottom with view controls
// (like viewDidLoad) for convenience)
//
// don't forget to register for notifications
@end
If you want a sample app (device only; iPod library), I can write one, but it won't be much more than this.