Unity 5.6.1: VideoPlayer.Play() or VideoPlayer.Prepare(); leads to temporary game freezes

Hi, everyone!

I'am using standard Unity VideoPlayer component.
Unity version is 5.6.1.

The problem is that the game freezes when I call VideoPlayer.Prepare(); or VideoPlayer.Play(); when trying to play video from URL. And resumes only when VideoPlayer operations are completed.

[quote]
STR:
1. set url to VideoPlayer;
2. Slow down your network connection;
3. call VideoPlayer.Prepare() or ViedoPlayer.Play();
4. Observe that whole game freezes until Video playback not started;
[/quote]

the code is something like this:

videoPlayer.url = url;
videoPlayer.Play();   // <<<- Whole game freezes until this operation is completed. It's looks like VideoPlayer is downloading video in UI thread and blocking it.

or this

videoPlayer.prepareCompleted += (source) =>
{ 
   source.Play ();
}
videoPlayer.url ="http://...";
videoPlayer.Prepare(); // Freeze starts from this point.

Also, when I try to use VideoPlayer.Prepare(); method I've got the same - the game freezes until Prepare() is completed and playback is started. Looks like that this operations works at the same UI thread and blocking it;

Is there any way to run VideoPlayer.Prepare() operation in another thread, or something like coroutine with it?

Looks like it's Unity VideoPlayer bug or I missed something?

Thanks in advance!

2 Likes

I believe that I have seen similar issues.

https://forum.unity3d.com/threads/seeing-steamvr-background-while-preparing-video-in-unity-5-6.471969/

Here is my interpretation of the VideoPlayer document.

If we registered for prepareCompleted, Prepare() should return right away without blocking.

Therefore, either we missed a step or it is a bug.

wesloc, thanks for your answer!

Unfortunately, registering callback for prepareCompleted has no effect at all.
As you can see from code listed above, I am already tried it.

I cannot figure out the purpose of Prepare() method. With it's current behavior it's seems that there is no effect from it.

Also I've tried this with Unity 2017.1.0.b7. Got the same result. And in additional got choppy video playback.

Hope it's a bug which will be fixed soon. Or some workaround will be found.

Right now, in the Editor it is fine, but when I build it to mobile, VideoPlayer.Prepare holds up the main thread.

My next steps are to try to

  • preload the video on a separate thread
  • save it to the mobile device
  • load it into the video player

3086736--232571--upload_2017-5-29_10-33-53.png

Once I can get something basic working, I will post it back here.

Cheers

  • preload the video on a separate thread

Good point. This could solve the problem. I will try it too.

Thanks.

I tried to preload in a separate thread, but the issue is squarely in VideoPlayer.Prepare().
I can live with it for a prototype. Did I miss something though? You cant stream?

Cheers

Looks like it’s a bug in VideoPlayer.Prepare().
I didn’t solved it too.

Should we move this issue to the Unity Answer section? I thought that there are unity engineers monitoring the forum?
We just want to know if we missed any step or this is a bug that will be addressed in the future.

wesloc, I am agree with you. It's looks like that we need help from Unity developers.

Maybe we can go open an Unity issue? I saw several related to Prepare() but none of them stated what we encounter clearly.

https://unity3d.com/search?refinement=issues&gq=prepare

I don't know how to open new issue in unity bug tracker. Looks like I have no rights to do it.
I've reported an issue using Unity Editor.

Hi everyone!

I've got an answer from QA. They say that our issue duplicates this:

https://issuetracker.unity3d.com/issues/videoplayer-dot-play-still-has-a-delay-after-using-videoplayer-dot-prepare

Let's vote for this issue!

@Im-Berzki499

Thanks. I just voted it up!! In addition, do you think it's worth to repost this question in Unity Answer. Maybe, someone with more experiences can come up a work around since we do not know when Unity will fix the issue.

I think It's good idea! We should use any possibility to solve this issue. It's serious blocker not just for us. I don't see anything wrong to ask for help. So, do it.

Maybe someone who has acces to Unity source code can take a look on VideoPlayer.Prepare() implementation and make a guess or figure out what is wrong with it.

Also, we can collaborate to solve this issue or to find some workaround.

Any updates?

Anyone able to solve this? I am facing the same issue on Android. For iOS and Desktop it works fine.

Looks like that we are all waiting for Unity developers to fix this bug.
For now, the only solution is to use some external video playback libraries.

We have the same problem here, unusable.
What we try to make is to have 1s clips that we use contextually, to react to player action. It’s a face in a screen, clips are 130x130 pixels, lasting 1s, but on Android it justs freezes the app and display like the 2 last frames. Totally useless.
Please unity make something about this

I have the same problem. When I try to play the video, everything hangs for about 4 seconds. I tried preparing the video in a background thread but Unity won’t allow it (has to be done in the main thread). Been stuck on this for days and I am out of ideas.