using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.IO;
public class TextMovieDownload : MonoBehaviour {
public MovieTexture movie;
public RawImage movieUI; //顯示的RawImage 需指定是哪一張圖
private string fileName ;
// Use this for initialization
void Start () {
fileName = Application.streamingAssetsPath + "/" + "Gem.ogv";;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.D)){
DownLoadMovie();
}
if(Input.GetKeyDown(KeyCode.G)){
GetMovie();
}
if(Input.GetKeyDown(KeyCode.P)){
PlayMovie();
}
if(Input.GetKeyDown(KeyCode.K)){
DeleteMovie();
}
}
private void DownLoadMovie(){
StartCoroutine(IEDownLoadMovie());
}
///// 儲存到電腦裡面
IEnumerator IEDownLoadMovie(){
WWW www = new WWW("https://docs.google.com/uc?authuser=0&id=0B4c7FeGn1Y0jWU9QdmJKSUNlMWc&export=download");
while (!www.isDone) yield return null;
if (www != null && www.isDone && www.error == null) {
System.IO.File.WriteAllBytes(fileName, www.bytes);
File.WriteAllBytes(fileName, www.bytes);
yield return null;
}
}
/////// 重電腦裡面抓取檔案 這邊要找一下UNITY官方的API 每個平台有點差別
private void GetMovie(){
WWW www = new WWW ("file://" + fileName);
movie= www.movie;
movieUI.texture = movie;
}
--- Android版本 不能加 "file://"
private void GetMovie(){
WWW www = new WWW (fileName);
movie= www.movie;
movieUI.texture = movie;
}
////// 重電腦裡面刪除檔案
private void DeleteMovie(){
if(System.IO.File.Exists(fileName)){
System.IO.File.Delete(fileName);
}
}
private void PlayMovie(){
movie.Stop();
movie.Play();
}
留言列表