如何在音乐播放器中设置音乐播放滑块 [英] How to set music playback slider in music player

查看:93
本文介绍了如何在音乐播放器中设置音乐播放滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中创建了具有上一个和下一个功能的音乐播放器.我想隐含歌曲播放滑块.该怎么做?

i created a music player with previous and next functionality in my app.i want to impliment song playback slider. how to do this?

推荐答案

使用 UISlider 将maxValue设置为当前播放歌曲的持续时间(以秒为单位),将minValue设置为0.

Use a UISlider setting the maxValue to the current playing song duration (in seconds) and the minValue to 0.

假设您正在使用 MPMusicPlayerController ,请使用 currentPlaybackTime 来获取播放曲目的当前时间,并使用该值每秒更新滑块

Assuming that you're using an MPMusicPlayerController use the currentPlaybackTime to get the current time of the playing track and use that value to update the slider each second

slider.value = musicPlayerController.currentPlaybackTime;
slider.minimumValue = 0;
slider.maximumValue = [musicPlayerController.nowPlayingItem valueForProperty:@"MPMediaItemPropertyPlaybackDuration"];

这篇关于如何在音乐播放器中设置音乐播放滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆