Use VideoPlayer to play video Url after MovieTexture is deprecated

When learning to use UnityWebRequestMultimedia.GetMovieTexture , I found that it has been deprecated. See if there is any other way to get MovieTexture.

It was found that MovieTexture was also deprecated, so we had to find alternative components and classes to use. The following is a simple usage of VideoPlayer.

Need to import the namespace using UnityEngine.Video;

1. Pass in the Url through the code

First add the AudioSource and Renderer components (if it is MeshRenderer, you need to add MeshFilter), and then add the VideoPlayer component to automatically bind the AudioSource and Renderer components (of course, you can also manually bind them yourself).

// 获得 Video 组件
VideoPlayer player = GetComponent<VideoPlayer>();

// 传入 URL
player.url = url;

// 设置绘制视频内容的位置【将视频内容绘制到用户指定的游戏对象的当前材质属性中】
player.renderMode = VideoRenderMode.MaterialOverride;

// 设置目标 Renderer
player.targetMaterialRenderer = GetComponent<Renderer>();

player.targetMaterialProperty = "_MainTex";

player.Play();

The above is the official sample code (the two attribute values ​​of targetMaterialProperty do not quite understand the usage).

The video rendering mode is set by the above player.renderMode property value.

2. Through components

1. Set the video source

You can set the properties in the component now, import Source in the code, or set it directly in the component.

Code setting method

// 通过url
player.url = url;

// 通过VideoClip
player.clip = videoclip;

2. Set the playback mode

 Code setting method

// 设置绘制视频内容的位置【将视频内容绘制到用户指定的游戏对象的当前材质属性中】
player.renderMode = VideoRenderMode.MaterialOverride;

Camera Far Plane and Camera Near Plane need to pass in the camera. Functionally, one is played on the far side of the camera, and the other is played on the near side of the camera.

Render Texture is the default mode, you need to create a Renderer Texture to use it together, and create a Target Texture property that is dragged into the Render Texture. Render Texture is inherited from Texture, and then dragged into a component that supports Texture (such as: RawImage).

 Material Override is basically the same as the above code setting and setting in the component.

It is unclear where the API Only can be used except that it cannot play the screen.

Guess you like

Origin blog.csdn.net/heaventianjianke/article/details/123360953