Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Show video on screen starts with grey screen

Discussion in 'Audio & Video' started by stefansmarius, Jul 6, 2023.

  1. stefansmarius

    stefansmarius

    Joined:
    Mar 9, 2021
    Posts:
    1
    Hi Unity users,

    We are working on a project where a car display has to play a new video when you interact.
    The problem is that for 1 second a grey screen appears before the new video is playing in the screen.

    How can we get rid of that grey screen and that the 2nd video is playing instantly?
    Thanks for all your help!

    Screenshot 2023-07-06 at 10.11.58.png
     
  2. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    499
    It takes some time for a video to be ready to play.
    If the RenderTexture is grey, you clear it or change the colour, you can to do this.
    Code (CSharp):
    1. private void ClearRenderTexture()
    2. {
    3.     RenderTexture rt = RenderTexture.active;
    4.     RenderTexture.active = videoPlayer.targetTexture;
    5.     GL.Clear(true, true, Color.clear);
    6.     RenderTexture.active = rt;
    7. }
    If you know what the next video is, you can have a second VideoPlayer prepared using the Prepare function and when you want to change Play the prepared video and start preparing the previous VideoPlayer with the next clips. Here is an example that loop clips without gaps.
    Code (CSharp):
    1. public class GaplessDemo : MonoBehaviour
    2. {
    3.     public VideoPlayer m_PlayingPlayer;
    4.     public VideoPlayer m_PreparingPlayer;
    5.     public VideoClip[] m_Clips;
    6.  
    7.     private int m_CurrentIndex = 0;
    8.  
    9.     private void Start()
    10.     {
    11.         m_PlayingPlayer.loopPointReached += LoopPointReached;
    12.         m_PlayingPlayer.clip = m_Clips[m_CurrentIndex];
    13.         m_PlayingPlayer.Play();
    14.  
    15.         m_PreparingPlayer.loopPointReached += LoopPointReached;
    16.         m_PreparingPlayer.clip = m_Clips[m_CurrentIndex + 1];
    17.         m_PreparingPlayer.Prepare();
    18.     }
    19.  
    20.     private void LoopPointReached(VideoPlayer source)
    21.     {
    22.         var player = m_PlayingPlayer;
    23.         m_PlayingPlayer = m_PreparingPlayer;
    24.         m_PreparingPlayer = player;
    25.  
    26.         m_PlayingPlayer.Play();
    27.  
    28.         m_CurrentIndex = (m_CurrentIndex + 1) % m_Clips.Length;
    29.         m_PreparingPlayer.clip = m_Clips[m_CurrentIndex];
    30.         m_PreparingPlayer.Prepare();
    31.     }
    32. }
    33.