How to force VideoPlayer.Prepare() immediatly?

Hello all!

I do this way:

videoPlayer.url = filename;
videoPlayer.Prepare();
videoPlayer.Play();

And in the next line I still get videoPlayer.length == 0d until the next frame. Is there any way to force Prepare() to take effect immediately, without waiting for Update (and ~0.2 seconds further)? I tried while (!videoPlayer.isPrepared) Sleep(100); but it ends up in an infinite loop, most likely with Prepare() relying on some internal events to proceed with processing the video.

This could work on another thread but you are doing this on the main thread blocking everything including the TimeManager. You should use Coroutine for that. You can find an example with WaitForSeconds.
https://docs.unity3d.com/ScriptReference/WaitForSeconds.html

1 Like