App freezes for ~35 secs on Android when navigating to new scene w/ Video

When navigating from menu to a Scene that contains 8, 1-minutes MP4 videos, that are played using new VideoPlayer script on RawImage component. I am using Unity 5.6.0b11 beta version.

In the scene that I am trying to navigate has prefabs that loads videos in list thumbnails, previously I was loading Images instead of Videos and it was working fine, now when trying to load video it freezes for than 38 seconds on Axon 7 (4GB RAM) and 32 seconds on One Plus 3 (6 GB RAM) but does not lags at all when playing on Unity Player itself.

button.onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
{
SceneManager.LoadSceneAsync(“SceneSponsors”);
StartCoroutine(CloseMenu());
}));

Is there a way, I can work around with the Slow Loading Scenes and pre-load them in Background when mainScene is loaded on the App start and navigate in need.

I saw somewhere Resources.Load() also makes it slow on Android Devices, but I tried removing all the image sprites and checked with just the Videos, but the problem was still there.

Until you get an official response, I wonder if you could split your loaded scene in 2: 1 with just the video bits and 1 with all else? Then you could load the non-video scene first and additive async load the video scene after?

1 Like

Hi luzanb,

With the description you’re giving, I cannot say whether the delay is due to Resource.Load() or actually starting the VideoPlayers. Here is a bit of information that may help you improve the situation in case VideoPlayers are the cause of the slowdown:

  • VideoPlayer is initialized with PlayOnAwake set to true, which will trigger clip loading as soon as your scene starts. You may want to make sure this is off if this is not the intended behaviour.
  • The VideoPlayer does not trigger a load of the whole clip when it starts; it just loads enough (header and read a few frames) to discover the nature of the clip (duration, frame rate, etc). How much the Android native implementation really loads, in turn, is not under our control. What is under our control however and that we’re not yet doing is perform this work in a separate thread. So although we have no control over how long this process is taking, at least when we implement asynchronous preparation on Android the main thread will not be stuck. This is on our list of things to do but I encourage you to log a bug about this to help with prioritization.

So in the mean time, if all you need is a thumbnail to represent a video that the user may want to play, I recommend making actual thumbnail images instead of relying on the VideoPlayer to provide this thumbnail for you.

Hope this helps,

Dominique
A/V developer at Unity.

Can you please explain me what you meant by 2? I couldn’t understand.

@Arkade I am already trying to navigate to my second scene which has Video Layout, from my home screen. Can you suggest, if there is a way to load the Scene 2 on background, during App start. For now App starts with Home Scene from where I am navigating to other scenes. If I could load it in background and make it ready on first load of app, I think that will also solve the problem.

BTW I am loading 2 different prefabs from the ObjectPool, and type of prefab depends on what data it gets from database. If there is a video available in data, it loads Prefab containing Video, and if there is no video available I loads prefab containing Image instead of video.

No, I don’t think Resource.Load() is the case. Because I tested the app by removing all Resources.Load() but the issue was still there.

I am also very sure that I have not missed it.

videoPlayer.playOnAwake = false;
audioSource.playOnAwake = false;

I am planning to report for a bug as you said. In the mean time, can you also guide me how can I achieve that thumbnail to represent a video, and only start load video when user clicks on that thumbnail. I am already loading VideoPlayer on my RawImage UI component through scripts.

I have attached images how my RawImage looks like. This is what RawImage Inspector looking like when it is not in play mode. And this is RawImage in Play mode, VideoPlayer is attached to it.

Is this the same think you were resembling as thumbnail or am I missing anything here.?

Thanks for help.

2995375--223121--rawimage_active_play.PNG
2995375--223122--rawimage_inactive_dev.PNG

For my case of problem. I had to make some changes on the VideoPlayer API Script I was using from this StackOverflow Question

In the script I was using from that link. The Co-routine was started inside the Start() function, that made the videos in 8 different prefab, to load at once even they were in pause mode.

So I added a new function PlayVideoOnClick() and attached it to the Click Event of the RawImage, so now the video will be loaded only if the RawImage is clicked.

Changed from

public void Start()
{
   Application.runInBackground = true;
   StartCoroutine(playVideo());

}

To

public void PlayVideoOnclick()
{
   Application.runInBackground = true;
   StartCoroutine(playVideo());

}

P.S: You can also see my YouTube Video Tutorial and Blog on Playing Videos smoothly in Unity.

1 Like