How to set music playback slider in music player

雨燕双飞 提交于 2019-12-12 12:18:16

问题


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


回答1:


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

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"];



回答2:


- (IBAction)slide:(id)sender{

    [musicPlayer setCurrentPlaybackTime: [slider value]];
}

- (void)actualizaSlider{

slider.value = musicPlayer.currentPlaybackTime;
slider.minimumValue = 0;

NSNumber *duration = [self.musicPlayer.nowPlayingItem valueForProperty:MPMediaItemPropertyPlaybackDuration];

float totalTime = [duration floatValue];

slider.maximumValue = totalTime;


来源:https://stackoverflow.com/questions/9258887/how-to-set-music-playback-slider-in-music-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!