Hello everyone! I do something like this
public class MainBehaivor : MonoBehaviour
{
public VideoPlayer videoPlayer;
// Start is called before the first frame update
void Start()
{
GameObject camera = GameObject.Find("Main Camera");
videoPlayer = camera.AddComponent<VideoPlayer>();
videoPlayer.playOnAwake = false;
videoPlayer.renderMode = VideoRenderMode.CameraNearPlane;
videoPlayer.isLooping = false;
videoPlayer.waitForFirstFrame = true; //with / without this line nothing changing at all
videoPlayer.skipOnDrop = false; //with / without this line nothing changing at all
}
void Update()
{
if (Input.GetKeyUp(KeyCode.Q)) Play("Video1.mp4");
if (Input.GetKeyUp(KeyCode.W)) Play("Video2.mp4");
}
private void Play(string name)
{
videoPlayer.url = Path.Combine(Application.streamingAssetsPath, name);
videoPlayer.Prepare(); //with / without this line nothing changing at all
videoPlayer.Play();
}
}
But every time on video changing - for a brief moment I see background color, empty screen without video.
I trying use two objects, set video to second and hide first after video start playing - but this doesn’t help either.
private void Play(string name)
{
if (videoPlayer1.gameObject.activeSelf)
ChangeVideo(name, videoPlayer1, videoPlayer2);
else
ChangeVideo(name, videoPlayer2, videoPlayer1);
}
private void ChangeVideo(string name, VideoPlayer old, VideoPlayer current)
{
old.Pause();
current.prepareCompleted += preparedCallback;
void preparedCallback(VideoPlayer source)
{
current.Play();
old.gameObject.SetActive(false);
old.clip = null;
current.prepareCompleted -= preparedCallback;
}
current.url = Path.Combine(Application.streamingAssetsPath, name);
current.gameObject.SetActive(true);
current.Prepare();
}
Hmm. Any ideas?