Playing videos with the Video Player API
Playing videos is as simple as manually adding a VideoPlayer
component in the Inspector panel to a GameObject at design time and associating a VideoClip
asset file from the Project panel, or providing the URL of an online resource.
Videos can be played on the camera’s far plane (appearing behind the scene content) or near plane (appearing in front of content – often with semi-transparency). Video content can also be directed to a RenderTexture
asset, which can then be displayed on a 2D or 3D object in the scene, via a material component. The internal texture that’s used by a VideoPlayer
component can also be mapped to a texture on screen – such as a UI RawImage
.
Scripting can be used to manage video playback for single videos and arrays (sequences) of video clips. Several recipes will be presented in this chapter to introduce these different ways of working with VideoPlayer
.
In this chapter, we will cover...