I have my video here and isPrepared is always false. I put Prepare in Start function, in onEnable function, Update Method… I don’t know what to do with this prepare thing?!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class SliderVideo : MonoBehaviour
{
[SerializeField] VideoPlayer video;
[SerializeField] Slider videoSlider;
[SerializeField] string videoName;
double videoTimeCache;
bool play;
bool isDone;
public bool IsPlaying
{
get { return video.isPlaying; }
}
public bool isLooping
{
get { return video.isLooping; }
}
public bool IsPrepared
{
get { return video.isPrepared; }
}
public bool IsDone
{
get { return isDone; }
}
public double Time
{
get { return video.time; }
}
public ulong Duration
{
get{ return (ulong)(video.frameCount/video.frameRate); }
}
public double NTime
{
get { return Time / Duration; }
}
//Start
private void Start()
{
LoadVideo(videoName); //Prepare();
}
//Update
private void Update()
{
if (!IsPrepared) return;
videoSlider.value = (float)NTime;
}
//Prepare Method
public void LoadVideo(string name)
{
video.url = System.IO.Path.Combine(Application.streamingAssetsPath, name+".mp4");
video.Prepare();
if (video.isPrepared)print(IsPrepared);
}
//Methods for Buttons
public void PlayVideo()
{
if (!IsPrepared) return ;
video.Play();
}
public void PauseVideo()
{
if (!IsPlaying) return;
video.Pause();
}
public void RestartVideo()
{
if (!IsPrepared) return ;
PauseVideo();
Seek(0);
}
public void Seek(float nTime)
{
if(!IsPrepared) return ;
nTime = Mathf.Clamp01(nTime);
video.time = nTime * Duration;
}
public void SeekSlider()
{
video.time = (videoSlider.value * Duration);
}
}