Kavita Kanwar
Kavita Kanwar

Reputation: 285

iOS Movement of UISlider thumb to track the progress of the movie

I'm implementing a video player in which I've taken UISlider to track the progress of the movie. This would mean that the thumb of the slider should be at the max value when the movie finishes.

I'm not able to achieve this. Movie finishes before thumb reaches at the end. Could anybody please help me understand what could be the issue?

This is the code that I've written:

//I'm setting the min, max values of the UISlider and calculating the current value
progressBar.minimumValue = 0.0;
progressBar.maximumValue = (float)movie.duration;
progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;

Upvotes: 0

Views: 1710

Answers (3)

Vlk
Vlk

Reputation: 99

Shouldn't it just be: progressBar.value = (float)movie.currentPlaybackTime ?

I mean, lets say movie duration is 60 sec, and the movie is at 15 sec (this is currentplaybacktime, I guess).

so:

  • progressbar min value is 0

  • progressbar max is 60

  • progressbar value should be between 0 and 60, and it is the value where the film is at right now: its 15.

Edit: You should also use: - setValue:animated:

Another idea: maybe you are not on the main thread. Make sure you are on the main thread when making ui changes.

Upvotes: 0

quaertym
quaertym

Reputation: 3961

Max value should be equal to the frame width:

progressBar.minimumValue = 0.0;
progressBar.maximumValue = progressBar.frame.size.width;
progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;

Upvotes: 0

Arthur Gevorkyan
Arthur Gevorkyan

Reputation: 2107

Just use progressBar.value = (float)movie.currentPlaybackTime; instead of progressBar.value = ((float)movie.currentPlaybackTime/(float)movie.duration) * progressBar.frame.size.width;

Upvotes: 0

Related Questions