How to change targetTexture of a video player during runtime?

Hi.

I want to make an application that can play different 360 videos.

These 360 videos have different resolutions and I want to change the size of renderTexture that is already set to a video player.

It seems that other people change it by creating a new renderTexture and set it to the video but it doesn’t work.

Here is the code below.


videoPlayer.url = Application.dataPath + “/360Video/files/1.mp4”;
renderTexture = new RenderTexture(1280, 720, 0, RenderTextureFormat.ARGB32);
renderTexture.wrapMode = TextureWrapMode.Clamp;
renderTexture.filterMode = FilterMode.Bilinear;
renderTexture.Create();
if (videoPlayer.targetTexture != null)
{
videoPlayer.targetTexture.Release();
}
videoPlayer.targetTexture = renderTexture;
videoPlayer.Prepare();

1 Like

Did you ever find a solution?

I ran into the same problem. Add one line to the the code and it will work.

YouGameObject.GetComponent().material.mainTexture = renderTexture;

or

YourRawImage.GetComponent().texture = renderTexture;

1 Like