- Home /
Playing Video in Unity 5 (on mobile)
I'm using Unity 5 free and wondering if there's a way to play back a movie (I'm using it for the intro movie the first time you play the game).
I'm fine with either loading the video directly or streaming it from the web if that's the only possible way.
All the answers I find mention Unity Pro, but they're also pre-Unity5, so I'm not sure if its changed since then.
When I try to bring a video file into Unity, it does not give me import options. I'm not able to assign it to a MovieTexture. I have Quicktime installed on Windows.
How does everyone else do it? Is there a plugin or an asset that would help me?
Once I build the app I'm just receiving an empty game screen that is continually flashing. I didn't have any errors pushing the build.
Any clue why?
Answer by psykojello2 · Nov 13, 2015 at 01:57 PM
Answering my own question...
I can't believe I didn't find this while searching the forums, but as of Unity 5, you can use Handheld.PlayFullScreenMovie() to play a video file in StreamingAssets. http://docs.unity3d.com/ScriptReference/Handheld.PlayFullScreenMovie.html
Read the info on file formats in there. I used VLC Player to export my movie to H.264 mp4 file.
I then Imported the file into an arbitrary folder under Assets in Unity (Not the streaming assets folder). Unity should recognize this file as a movie and give you some options in the inspector.
NOW, move the file into StreamingAssets. If you do it directly, it doesn't recognize it as a movie for some reason. *shrug.
I hope this helps someone!
Works brilliantly, cheers for the fix. If you put the Handheld player call inside an IEnumerator function and do a
yield return new WaitForEndOfFrame();
then you can set up a different function to start when the video is finished or cancelled.
I cant see the video in my unity editor, the vid only show up when I install the build in my mobile?
Answer by guruDeRareKing006 · Mar 04, 2017 at 09:11 AM
Hi all Guru here , i was searching for the same but after a pro long struggle i have made it work..
I just wanted people to know about the complete process here itself..
Question : How to playback a video in android platform using unity c-sharp ?
Answer :
Step 1< --- Make sure about the formats and the settings of the video , mp4 h.264 (640x480) worked for me.
Step 2< --- Create a folder inside your Assets folder and name it as "StreamingAssets" (without space , it is case sensitive). Place your video in the folder.
Step 3< --- Write a new c-sharp script using the code below :
"using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;"
public class playbackVideoHandHeld : MonoBehaviour {
private string movie = "yourVideoNameHere.mp4";
public int sceneNumber;
// Use this for initialization
void Start ()
{
StartCoroutine(streamVideo(movie));
}
private IEnumerator streamVideo(string video)
{
Handheld.PlayFullScreenMovie(video, Color.black, FullScreenMovieControlMode.Full, FullScreenMovieScalingMode.AspectFill);
yield return new WaitForEndOfFrame();
Debug.Log("The Video playback is now completed.");
SceneManager.LoadScene (sceneNumber);
}
}
Step 4< --- Create an empty GameObject and attach the script to it.
Note : You will not see the video playing in the editor or by using build and run , you have to build the app and install in order to check it.
Step 5< --- The step four's note session is the most important part where i have spent a loads of time.
Note : If unity throws error while building it to an apk which says like something went wrong in the AndroidManifest.xml or some winsdk error just change the Minimum API Level under Other Settings of the Player Settings and see which one works for you.
Thanks, Guru
HI Guru , This works . great !!!
Can you please let me know if I want to know play the same in VR mode what changes shall i do. As the video is playing on start , not entering the vr mode although i hv attached the vr settings.
Thanks , Sutapa
Hi Guru! i just want to ask why does my video is looping from the start even though it hasn't finish playing. The start of the video is looping. I use the same process as you mention above. thanks!
Answer by brunopava · Nov 13, 2015 at 01:57 PM
There is two plugins that can do that on mobile. Mobile Movie Texture and Easy Movie Texture.
thanks @brunopava!
However I can confirm that the built in Handheld.PlatFullScreen$$anonymous$$ovie() works on iOS and Android with Unity 5 (Free).
Hi Bruno, do you know if the Easy $$anonymous$$ovie Texture plugin works on the FREE version of Unity 5.x? Thanks!
Answer by brunopava · Nov 13, 2015 at 12:32 PM
https://www.assetstore.unity3d.com/en/#!/content/2449
https://www.assetstore.unity3d.com/en/#!/content/10032
These two work fine. I have tested them.
$$anonymous$$obile $$anonymous$$ovie Texture isn't on the store any longer.
I recently purchased Easy $$anonymous$$ovie Texture and it works in the Unity Editor, but I get this error when I build to Android: I'm using Unity 5.5.0f3, and build for Android 4.4 $$anonymous$$it $$anonymous$$at, and Android 6 $$anonymous$$arshmallow. It seems like a pretty straight forward set-up, but I'm not sure why it's not working.
There is no need for any plugins. PlayFullScreen$$anonymous$$ovie is built into Unity - https://docs.unity3d.com/ScriptReference/Handheld.PlayFullScreen$$anonymous$$ovie.html