Video Player shows before video loads

I have a video that plays over a cube prefab. The video source is a url. The problem is, you see a grey box as the video loads before it plays. I set wait for first frame but that doesn’t seem to make a difference. Is there a way that I can make the player invisible until the video is ready to play?

Ensure the cube’s Renderer (e.g., MeshRenderer) is disabled initially so that it doesn’t display the grey box.

Use the VideoPlayer.prepareCompleted event to enable the renderer only after the video is prepared and ready to play.

Here’s an example script to achieve this:

using UnityEngine;
using UnityEngine.Video;

public class VideoLoader : MonoBehaviour
{
public VideoPlayer videoPlayer;
public Renderer cubeRenderer;

void Start()
{
    // Ensure the renderer is initially disabled
    cubeRenderer.enabled = false;

    // Add the prepareCompleted event listener
    videoPlayer.prepareCompleted += OnVideoPrepared;

    // Prepare the video
    videoPlayer.Prepare();
}

void OnVideoPrepared(VideoPlayer vp)
{
    // Enable the renderer when the video is ready
    cubeRenderer.enabled = true;

    // Play the video
    videoPlayer.Play();
}

}

This approach ensures that the Tiktok 18 video player remains invisible until the video is fully loaded and ready to play.

1 Like