http://blog.csdn.net/awnuxcvbn/article/details/17618919
Click here to download the video converter, the converter will convert other formats into OGV format, directly recognized by unity, do not need to install QuickTime do not need to restart, more importantly than the MOV into unity to be clear.
[CSharp]View PlainCopy
- Using Unityengine;
- Using System.Collections;
- Public class Movietest:monobehaviour
- {
- //Movie Textures
- Public movietexture Movtexture;
- void Start ()
- {
- //Set the main texture of the current object as the movie texture
- Renderer.material.mainTexture = movtexture;
- //Set movie texture playback mode to loop
- Movtexture.loop = true;
- //startcoroutine (Downloadmovie ());
- }
- void Ongui ()
- {
- if (Guilayout.button ("play/Continue"))
- {
- / /play/continue playing video
- if (!movtexture.isplaying)
- {
- Movtexture.play ();
- }
- }
- if (Guilayout.button ("pause playback"))
- {
- //Pause playback
- Movtexture.pause ();
- }
- if (Guilayout.button ("Stop playing"))
- {
- //Stop playing
- Movtexture.stop ();
- }
- }
- IEnumerator Downloadmovie ()
- {
- www www = new www ("http://127.0.0.1/Head.ogv");
- Yield return www;
- Debug.Log (Time.time);
- Movtexture = Www.movie;
- //Set the main texture of the current object as the movie texture
- Renderer.material.mainTexture = movtexture;
- Movtexture.loop = true;
- }
- }
Plus sound
[CSharp]View PlainCopy
- Using Unityengine;
- Using System.Collections;
- Public class Movietest:monobehaviour
- {
- //Movie Textures
- Public movietexture Movtexture;
- //Sound
- Public Audiosource Movaudio;
- void Start ()
- {
- //Set the main texture of the current object as the movie texture
- Renderer.material.mainTexture = movtexture;
- //Set movie texture playback mode to loop
- Movtexture.loop = true;
- //startcoroutine (Downloadmovie ());
- }
- void Ongui ()
- {
- if (Guilayout.button ("play/Continue"))
- {
- / /play/continue playing video
- if (!movtexture.isplaying)
- {
- Movtexture.play ();
- Movaudio.play ();
- }
- }
- if (Guilayout.button ("pause playback"))
- {
- //Pause playback
- Movtexture.pause ();
- Movaudio.pause ();
- }
- if (Guilayout.button ("Stop playing"))
- {
- //Stop playing
- Movtexture.stop ();
- Movaudio.stop ();
- }
- }
- IEnumerator Downloadmovie ()
- {
- www www = new www ("http://127.0.0.1/Head.ogv");
- Yield return www;
- Debug.Log (Time.time);
- Movtexture = Www.movie;
- //Set the main texture of the current object as the movie texture
- Renderer.material.mainTexture = movtexture;
- Movtexture.loop = true;
- }
- }
Note: 1280*720 resolution of video played in this way does not produce black edges.
Previously just testing, no actual use, found that multiple clicks to play will have a memory leak. The following method solves
[CSharp]View PlainCopy
- Using Unityengine;
- Using System.Collections;
- Public class Webmovie:monobehaviour {
- //Movie Textures
- Public movietexture Movtexture;
- www www;
- void Start ()
- {
- }
- void Ongui ()
- {
- if (Guilayout.button ("load Video"))
- {
- Startcoroutine (Downloadmovie ());
- }
- if (Guilayout.button ("play/Continue"))
- {
- / /play/continue playing video
- if (!movtexture.isplaying)
- {
- Movtexture.play ();
- }
- }
- if (Guilayout.button ("pause playback"))
- {
- //Pause playback
- Movtexture.pause ();
- }
- if (Guilayout.button ("Stop playing"))
- {
- //Stop playing
- Movtexture.stop ();
- }
- if (Guilayout.button ("Unload Memory"))
- {
- Renderer.material.mainTexture = null;
- Movtexture = null;
- www = null;
- Resources.unloadunusedassets ();
- }
- }
- IEnumerator Downloadmovie ()
- {
- www = new www ("http://127.0.0.1/mumaren.ogv");
- Yield return www;
- Debug.Log (Time.time);
- Movtexture = Www.movie;
- //Set the main texture of the current object as the movie texture
- Renderer.material.mainTexture = movtexture;
- Movtexture.loop = true;
- }
- }
is to destroy the WWW object, but before this, it is necessary to remove other objects to the WWW reference, such as the material ball of the main map, the declaration of the movtexture, and perhaps AudioClip.
Unity3d playing video