I have a custom slider whose min and max values are 0 and 1 respectively. I want to set the thumb at a particular duration(at 1s) of the file. How do I do that calculation? Currently, I'm multiplying the slider开发者_运维技巧 value with the total duration of file to get the desired position. But, now depending on my preference, how do I set the thumb? Please advise.
The easiest thing would be to set the max value of the slider to the length of your file. It's a settable property, so just
slider.maximumValue = fileDuration;
would work. Then, you can just set the value for however long into the file you want.
If you can't do that for other reasons, you need to normalize the position you want by the file length (that is, divide the position you want by the file duration to find the value):
slider.value = (desiredPosition / fileDuration);
Note that with this, if desiredPosition
is the entire length of the file, you get 1 (the maximum value of the slider by default)
精彩评论