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!
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.
private void ClearRenderTexture()
{
RenderTexture rt = RenderTexture.active;
RenderTexture.active = videoPlayer.targetTexture;
GL.Clear(true, true, Color.clear);
RenderTexture.active = rt;
}
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.
public class GaplessDemo : MonoBehaviour
{
public VideoPlayer m_PlayingPlayer;
public VideoPlayer m_PreparingPlayer;
public VideoClip[] m_Clips;
private int m_CurrentIndex = 0;
private void Start()
{
m_PlayingPlayer.loopPointReached += LoopPointReached;
m_PlayingPlayer.clip = m_Clips[m_CurrentIndex];
m_PlayingPlayer.Play();
m_PreparingPlayer.loopPointReached += LoopPointReached;
m_PreparingPlayer.clip = m_Clips[m_CurrentIndex + 1];
m_PreparingPlayer.Prepare();
}
private void LoopPointReached(VideoPlayer source)
{
var player = m_PlayingPlayer;
m_PlayingPlayer = m_PreparingPlayer;
m_PreparingPlayer = player;
m_PlayingPlayer.Play();
m_CurrentIndex = (m_CurrentIndex + 1) % m_Clips.Length;
m_PreparingPlayer.clip = m_Clips[m_CurrentIndex];
m_PreparingPlayer.Prepare();
}
}