How do I create a music progress indicator/control, like the iPod app? [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this questionI'm writing an iPod app replacement, and in my "now playing" view I want to have a progress indicator like the iPod app, that shows current position, and allows the user to drag to change the play position.
How do I 开发者_开发百科do that?
Do I use a UISlider and UIProgressView?
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.
 加载中,请稍侯......
      
精彩评论