Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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

Discussion in '5.6 Beta' started by luzanb, Mar 15, 2017.

  1. luzanb

    luzanb

    Joined:
    Feb 25, 2017
    Posts:
    18
    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.
     
  2. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    655
    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?
     
    luzanb likes this.
  3. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    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.
     
  4. luzanb

    luzanb

    Joined:
    Feb 25, 2017
    Posts:
    18
    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.
     
    Last edited: Mar 16, 2017
  5. luzanb

    luzanb

    Joined:
    Feb 25, 2017
    Posts:
    18
    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.
     

    Attached Files:

  6. luzanb

    luzanb

    Joined:
    Feb 25, 2017
    Posts:
    18
    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

    Code (csharp):
    1. public void Start()
    2. {
    3.    Application.runInBackground = true;
    4.    StartCoroutine(playVideo());
    5.  
    6. }
    To

    Code (csharp):
    1. public void PlayVideoOnclick()
    2. {
    3.    Application.runInBackground = true;
    4.    StartCoroutine(playVideo());
    5.  
    6. }
    P.S: You can also see my YouTube Video Tutorial and Blog on Playing Videos smoothly in Unity.
     
    DominiqueLrx likes this.