开发者

How do I create a music progress indicator/control, like the iPod app? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

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 question

I'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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜