using System.Runtime.InteropServices;
using UnityEngine;
using System.Collections;
using Assets;
public class PlayVideo : MonoBehaviour
{
public string url;
public MovieTexture movieTexture;
public WWW www;
void Start()
{
url = "file:///D:/video/sample.ogg";//本地视频
// url = "http://www.unity3d.com/webplayers/Movie/sample.ogg ";//外部视频
StartCoroutine(DownLoadMovie());
}
private IEnumerator DownLoadMovie()
{
www = new WWW(url);
Debug.Log(Time.time);
movieTexture = www.movie;
audio.clip = movieTexture.audioClip;
renderer.material.mainTexture = movieTexture;
movieTexture.loop = true;
yield return www;
}
void Update()
{
Debug.Log("movieTexture.isReadyToPlay" + " " + movieTexture.isReadyToPlay);
Debug.Log("www.isDone" + " " + www.isDone);
Debug.Log("movieTexture.duration" + " " + movieTexture.duration);
Debug.Log("movieTexture.isPlaying" +" "+ movieTexture.isPlaying);
}
void OnGUI()
{
if (GUILayout.Button("播放/继续"))
{
//播放/继续播放视频
if (!movieTexture.isPlaying)
{
movieTexture.Play();
audio.Play();
}
}
if (GUILayout.Button("暂停播放"))
{
//暂停播放
movieTexture.Pause();
audio.Pause();
}
if (GUILayout.Button("停止播放"))
{
//停止播放
movieTexture.Stop();
audio.Stop();
}
}
}
网友评论