- Home /
Question by
proVeritas_vk · Aug 21, 2018 at 07:57 PM ·
videosliderinteractionprogress-bar
Interactive movie slider
Hello people! I want to make slider control that will follow movie clip (on simple Unity Video Player component, camera far plane) on Android device. Play/Pause need to be on touch (I don't need all controls, just slider that will show movie progress). I made this with:
[SerializeField] VideoPlayer videoPlayer;
[SerializeField] Slider slider;
void Update()
{
slider.value = (float)videoPlayer.frame / (float)videoPlayer.frameCount;
//or
//slider.value = (float)videoPlayer.time / Duration;
}
public ulong Duration
{
get
{
return (ulong)(videoPlayer.frameCount / videoPlayer.frameRate);
}
}
And, that works. But, problem is when I try to make this slider interactive (on mouse press in Unity Editor/on touch in build). How can I do that? I tried with:
float _time;
// this method I connect with slider's OnValueChanged in Unity:
public void SkipVideo(float time)
{
// time is from 0 to 1
float delta = time - _time;
// User try to seek video:
if (Mathf.Abs(delta) > .001f)
{
// this works, but without any code in Update().
// This jump to a certain point of video, but
//then I don't have progress bar, just interactive slider
videoPlayer.frame = (long)(time * (float)videoPlayer.frameCount);
// when I have that code in Update() it works weird
}
_time = time;
}
I also tried with OnPointerDown() function, but no success.
How can I combine slider progress and it's interactivity?
Comment