unity-game-enginetexturesvideo-player

White frame before video plays in Unity instead of a custom thumbnail


I load a thumbnail before the video starts to play, but later when the video is playing, there is first a white frame and then the video is playing. How can I avoid this white frame??

Here is my code-

video.GetComponent<RawImage>().texture = thumbnailTex;
//Play the video:
RenderTexture rt = new RenderTexture(1920, 1080, 16, RenderTextureFormat.ARGB32);
rt.Create();
video.GetComponent<RawImage>().texture =rt;
video.GetComponent<RawImage>().targetTexture=rt;
video.GetComponent<VideoPlayer>().url = "www....";
video.GetComponent<VideoPlayer>().Play();
// white frame, and then the video is playing

Solution

  • You need to wait first and test if the video is ready to play

    It would be better if it's not already to have the above code in a coroutine. What is happening is you call play before the player has had a chance to download/load the first frame. Then display your rendertexture.

    video.GetComponent().url = "...";
        video.GetComponent().Prepare(); 
        while (!video.GetComponent().isPrepared) 
            yield return new WaitForEndOfFrame(); 
        video.GetComponent().frame = 0; //just incase it's not at the first frame
        video.GetComponent().Play();
        //now display your render texture