Unity3D 视频播放

视频播发有两种方法:
(1)plane上
using UnityEngine;
using System.Collections;

public class Test: MonoBehaviour
{

//电影纹理
public MovieTexture movTexture;

void Start()
{
//设置当前对象的主纹理为电影纹理
gameObject.GetComponent<Renderer>().material.mainTexture = movTexture;
//设置电影纹理播放模式为循环
movTexture.loop = true;
}

void OnGUI()
{
if(GUILayout.Button("播放/继续"))
{
//播放/继续播放视频
if(!movTexture.isPlaying)
{
movTexture.Play();
}

}

if(GUILayout.Button("暂停播放"))
{
//暂停播放
movTexture.Pause();
}

if(GUILayout.Button("停止播放"))
{
//停止播放
movTexture.Stop();
}
}
}
(2)摄像机上播放

using UnityEngine;
using System.Collections;

public class Test: MonoBehaviour
{

//电影纹理
public MovieTexture movTexture;

void Start()
{
//设置电影纹理播放模式为循环
movTexture.loop = true;
}

void OnGUI()
{
//绘制电影纹理
GUI.DrawTexture (new Rect (0,0, Screen.width, Screen.height),movTexture,ScaleMode.StretchToFill);

if(GUILayout.Button("播放/继续"))
{
//播放/继续播放视频
if(!movTexture.isPlaying)
{
movTexture.Play();
}

}

if(GUILayout.Button("暂停播放"))
{
//暂停播放
movTexture.Pause();
}

if(GUILayout.Button("停止播放"))
{
//停止播放
movTexture.Stop();
}
}

}
(3)视频大小调控
transform.localScale = new Vector(1,1,1);
(4)移动设备播放
using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

void OnGUI()
{
if (GUI.Button (new Rect (20,10,200,50), "PLAY ControlMode.CancelOnTouch"))
{
Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.CancelOnInput);
}

if (GUI.Button (new Rect (20,90,200,25), "PLAY ControlMode.Full"))
{
Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Full);
}

if (GUI.Button (new Rect (20,170,200,25), "PLAY ControlMode.Hidden"))
{
Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Hidden);
}

if (GUI.Button (new Rect (20,250,200,25), "PLAY ControlMode.Minimal"))
{
Handheld.PlayFullScreenMovie("test.mp4", Color.black, FullScreenMovieControlMode.Minimal);
}

}

}

posted on 2016-10-19 13:28  3137102247  阅读(171)  评论(0编辑  收藏  举报

导航