how to play video in unity ?

What is Unity Video Player ?

Unity has a component called a Video Player. This component can be attached to any GameObject in your unity scene. It allows you to assign a video file to it for playback within your game / app.

This video player can be rendered to a camera’s near or far planes or any GameObject. It can also render itself to a RenderTexture, which can be attached to any GameObjects in your scene as a material.

This allows you to create an object like RawImage, Cube, Sphere and any other Unity’s GameObject in your scene that will play a movie on it.

The video player also gives you playback options, such as the ability to play a clip on awake, or to loop the clip or to manage the speed of video playing.

Video Playback Unity Tutorial

Follow the steps to integrate video on unity

1. Play Video in Unity - 3D object

1.1 Create any 3D object
To create a 3D cube for example : Click the “GameObject” menu -> 3D Object -> Cube.

Play video in Unity

1.2 Video Player Unity
Add the video player component to that created cube.

Play video in Unity

1.3 Assign Video
Now, add the video which you want to play to your assets folder.
And then assign that video to the Video Clip field in the Video Player component of the cube.

1.4 Video Texture Unity
Material property -> _MainTex
This means that when the Video Player component is attached to a GameObject that has a Renderer, it automatically assigns itself to the Texture on that Renderer (because this is the main Texture for the GameObject)

2. Play Video in Unity - Background

You can also play video in unity background and have different properties for that.

2.1 Video Player Unity
Add the video player component to the Main Camera from Add Component.

2.2 Assign Video
Now, add the video which you want to play in the background to your assets folder.
And then assign that video to the Video Clip field in the Video Player component of the Main Camera.

2.3 Renderer Mode
After assigning video to the Video Player Component of the Main Camera, you can make changes to the Renderer Mode field of Video Player Component and adjust how you want to play your video.

Play video in Unity

The default value of this field is “Camera Far Play”, so it will display all other objects. Other values work differently, you can check and set according to your need.

This will play video on the whole screen. Even you can play multiple videos on the same screen by assigning different Video Components to different GameObjects.

Like we have set up one on the background and one on the cube so it will look something like the following image when you run your Unity scene, it will Play Video in Unity game/app.

Play video in Unity

There are different fields available in the Video Player component, like…

1. Play On Awake

This will play a video on Awake.

2. Loop

This will allow you to play video continuously on loop.

If you set it to false then it will show the video’s last frame after playing the video once.

Like above there are many different fields so you can manage sound of the video, it’s speed, it’s Renderer Mode and many more.

Play video in Unity

Video On Unity - Supported Format

Unity’s VideoPlayer uses native audio and video decoding libraries. It is the user’s responsibility to use videos that match the requirements for the target platform, so there won’t be any issue of video not playing on some of the devices.

The VideoClipImporter offers an option to transcode the VideoClip assets into one of  H.264, H.265 or VP8 video codecs, along with a few options to experiment with, such as resolution. This uses the matching codec for audio tracks: AAC and Vorbis respectively.

* Android: Supported Media Formats

* Windows: Supported Media Formats, H.265

Video On Unity - Video Resolution & Audio Tracks

While implementing video on unity the biggest problem is to manage the resolution of the video for different screen size of different devices. Initially I was using 1080 resolution video for all but it wasn’t looking that good on different devices. So, after some research I finally found some details for Android, which are as follows.

* Support for resolutions above 640 x 360 is not available on all devices. Runtime checks are done to verify this and failures will cause the movie to not be played.

* For Jelly Bean/MR1, movies above 1280 x 720 or with more than 2 audio tracks will not be played due to bugs in the OS libraries.

* For Lollipop and above, any resolution or number of audio channels may be attempted, but will be constrained by device capabilities.

I hope you find this blog helpful while integrating the Video On Unity scene.
Feel free to contact, if you have any questions or need help at any place while implementing Video Playback Unity.

About the author

Co-Founder at Inventive9 Experienced Game Developer with a demonstrated history of working in the information technology and services industry. Skilled in Unity3D, Cocos2d, Box2D, Objective-C, HTML, Android, iOS. Strong engineering professional with an MCA focused on Computer Software Engineering from the Department of Computer Science.
10 Responses
  1. Kay

    Hello! This is my first visit to your blog! We are a team of volunteers and starting a new project in a community in the same niche. Your blog provided us useful information to work on. You have done a marvelous job!

  2. Roberto

    I am sure this post has touched all the unity users, its really really fastidious article on building up unity code.

  3. mollie

    Normally I don’t learn post on blogs, however, I wish to say that this write-up very pressured me to try and do so!
    great post.

  4. elvira

    Amazing blog! Is your theme custom made or did you download it from somewhere?

    A theme like yours with a few simple adjustments would really make my blog stand out. Please let me know where you got your design. Thank you