更新时间:2023-02-27 08:43:47
使用 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"];