- Home /
Question by
ZeBraNS · Aug 13, 2018 at 02:10 PM ·
scripting problemuivideo
Video Player time slider
Hi,
I would like to have UI slider that controls the video player in the scene. can someone help me with writing this script right?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class VideoSlider : MonoBehaviour {
private VideoPlayer videoPlayer;
private Slider slider;
void Start ()
{
videoPlayer = GetComponent<VideoPlayer> ();
slider = GetComponent<Slider>();
slider.minValue = 0;
slider.maxValue = CalculateLengh();
}
void Update ()
{
slider.value = videoPlayer.time;
}
public void MoveSlider()
{
videoPlayer.time = slider.value;
}
double CalculateLengh()
{
double fraction = (double)videoPlayer.frameCount / (double)videoPlayer.frameRate;
return fraction;
}
}
Comment
Answer by ZeBraNS · Aug 15, 2018 at 12:59 PM
Still having the problem to figure this out
public class SliderNew : MonoBehaviour {
public Slider slider;
private VideoPlayer videoPlayer;
void Awake()
{
videoPlayer = GetComponent<VideoPlayer>();
}
double PlayedFraction()
{
double fraction = (double)videoPlayer.frame / (double)videoPlayer.clip.frameCount;
return fraction;
}
public void Slide()
{
slider.value = fraction;
}
}