Unity plays external video

Source: Internet
Author: User

Summary: Unity supports playback video formats with. mov,. mpg,. mpeg,. mp4,. avi, and. asf. Simply drag and drop the corresponding video file into Project view, and it will automatically generate the corresponding Movietexture object.

There are two ways to play video game in 1.unity3d, the first is to play in the game object, just like creating a plane object in the game world, and the camera is directly shining on the surface. The second is to play the video at the GUI level. Playing a video is very much like a map, because the movietexture that play the video belong to the sub-class of the map texture

Film Texture public    movietexture movtexture;    void Start ()    {        Transform.localscale = new Vector3 (1, 1, 1);        Sets the main texture of the current object for the movie texture        renderer.material.mainTexture = movtexture;        Set the movie texture playback mode to loop        Movtexture.loop = true;    }    void Ongui ()    {        if (Guilayout.button ("Play/Continue") {//            play/Resume video            if (!movtexture.isplaying)            {                movtexture.play ();            }        }        if (Guilayout.button ("Pause play"))        {            //Pause play            movtexture.pause ();        }        if (Guilayout.button ("Stop playing"))        {            //stop playing            movtexture.stop ();        }    }

  

The second way to play the video is based on the GUI. You can delete the plane object you just created and the world directed light, and bind the script directly to the camera object. Script control is basically the same as hanging on plane.

2.unity Play external video, you can use the WWW class to load the video, which involves the knowledge of the association process.

The process is equivalent to threading, here is an article in-depth explanation of the process. http://dsqiu.iteye.com/blog/2029701

The process is not a thread, nor is it executed asynchronously. The Monobehaviour and the update function are also executed in Mainthread. Using the coprocessor you don't have to worry about syncing and locking issues.

Here's another article about the http://blog.csdn.net/huang9012/article/details/38492937.

Film Texture public movietexture movtexture;        void Start () {//Set movie texture playback mode to loop//movtexture.loop = true;        Startcoroutine (Loadmovie ());            Debug.Log ("Download Complete"); } IEnumerator Loadmovie () {//config file path//string configpath = "file:///" + Application.datapath + "/confi        G/config.txt ";        String Configpath = "E:/config.txt";        Video file path//string url = "file:///" + Application.datapath + "/MOVIES/OLDBOY.OGV";        String url = "file:///" + "E:/U3DEXERCISE/OLDBOY.OGV";        String url = ""; using (StreamReader reader = new StreamReader (configpath)) {URL = reader. ReadToEnd ().        Trim ();        //www is a very common tool class used in unity development, providing functionality for general HTTP access, as well as dynamically downloading images, sounds, videos, and unity resources from the Web. WWW parameters must be added "file:///" as the prefix file:///is the protocol header, can be resolved to a local file path//Common http://,ftp://, and file:///www www = new www ("File        :///"+ URL");        Movtexture = Www.movie;   while (!movtexture.isreadytoplay) {         Debug.Log (www.progress);    } yield return www; } void Ongui () {//Draw the movie texture GUI.        Drawtexture (New Rect (0, 0, Screen.width, screen.height), Movtexture, Scalemode.stretchtofill);                if (Guilayout.button ("Play/Continue") {//play/Resume Video if (!movtexture.isplaying) {            Movtexture.play ();        }} if (Guilayout.button ("Pause play")) {//Pause play movtexture.pause ();        } if (Guilayout.button ("Stop playing")) {//Stop playing movtexture.stop (); }    }

  

Unity plays external video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.