如何创建音乐进度指示器/控件,例如 iPod 应用程序?

发布于 2024-11-05 07:51:27 字数 1435 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_失温 2024-11-12 07:51:27

到处省略了一些东西,但是插入就足够了。

// .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

如果你想要一个示例应用程序(仅限设备;iPod 库),我可以写一个,但不会比这多多少。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文