Unity學習之—視頻播放問題

bug再現:

當把播放的視頻拖拽到MovieTexture上,打包後 即使將這個視頻刪除了,程序仍可以播放視頻。

movieTexture.Play(); 直接播放視頻。經過羣裏大神指導發現,當你拖拽物體到對應的腳本時候unity自己會關聯資源關係,從而直接打包到項目中。

www動態加載播放視頻代碼:

using UnityEngine;
using System.Collections;
 
public class MovePlay : MonoBehaviour {
 
    public MovieTexture movieTexture;
        public WWW www;
    string datapath;
 
	// Use this for initialization 
	void Start () { 
        datapath = Application.streamingAssetsPath+ "/DLXX.ogv";
        Debug.Log("file://" + datapath  );
        StartCoroutine(OnLoadMove());
    }
	
	// Update is called once per frame
	void Update () {
	
	}
    void OnGUI() {
        if (GUILayout.Button("play")) {
            movieTexture.Play();
        }
 
    }
    IEnumerator OnLoadMove() {
        www = new WWW("file://"+datapath);
        Debug.Log(www);
        yield return www;
        movieTexture = www.movie;
        renderer.material.mainTexture = movieTexture;
        movieTexture.loop = true;
       // movieTexture.Play();
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章