Search Unity

Video VideoPlayer Component starts with black

Discussion in 'Audio & Video' started by letsgetnerdy, Apr 20, 2020.

  1. letsgetnerdy

    letsgetnerdy

    Joined:
    Jul 4, 2017
    Posts:
    2
    Hello,
    i'm developing an AR APP with different videos as content. i'm using the video player component. The videos are streamed from the internet (mp4 format).
    Under iOS I have the problem that the videos are completely black for a few seconds when starting. On Android and Windows everything is ok. I have already tested different video formats - without success.
    I cannot explain why the video surface remains black for a few seconds. Do you have an idea?
    Unity Version 2018.4.17
    Here is my script for loading the video.

    Code (CSharp):
    1.  
    2. IEnumerator PlayVideo () {
    3.         player.Prepare ();
    4.         WaitForSeconds waitForSeconds = new WaitForSeconds (1f);
    5.  
    6.         while (!player.isPrepared) {
    7.             yield return waitForSeconds;
    8.             break;
    9.         }
    10.  
    11.      
    12.         player.Play ();
    13.  
    14.     }
    15. //StartCoroutine (PlayVideo ());
    16.  
     
    Last edited: Apr 20, 2020
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi!

    You're possibly falling into an ambiguity of what isPrepared means. On Apple platforms, the video becomes "prepared" as soon as the description becomes available (number of tracks, resolution, etc), but this isn't waiting for buffering to be sufficient for stable playback like it does on the two other platforms you're mentioning. So Apple's media API (AVFoundation) probably waits some more for this buffering to happen before making playback possible.

    An alternative you may try is to wait for the first frameReady event (after enabling these events with sendFrameReadyEvents = true). You then invoke Pause() instead of Play(), and only invoke Play() when you actually receive the first frame via the frameReady event.

    This may help sidestep this behaviour difference between platforms.

    Please let us know if this approach works for you!

    Dominique Leroux
    A/V developer at Unity
     
    letsgetnerdy likes this.