Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set music playback slider in music player

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

like image 835
Vivek Parikh Avatar asked Dec 05 '22 18:12

Vivek Parikh


1 Answers

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"];
like image 60
Francesco Avatar answered Dec 09 '22 14:12

Francesco