0
我想從網址下載視頻(用於測試的兔子視頻),然後使用視頻播放器組件播放它。無法播放使用VideoPlayer在Unity下載的視頻剪輯
我這裏的問題是,如果我通過一個預先下載的片段或URL在編輯模式下的視頻播放器可播放影片沒有任何問題,但是當我嘗試動態添加VideoPlayer組件到我的遊戲對象,並指定視頻剪輯到視頻播放器,它從不播放視頻。在播放模式下,剪輯選項在VideoPlayer組件中始終顯示爲空。當通過腳本完成時,添加url也不起作用。
這是我的腳本,下載視頻並將其分配給錄像機。
public class DownloadScript : MonoBehaviour
{
private WWW Url;
private VideoPlayer Player;
public VideoClip clip;
public float test;
// Use this for initialization
void Start()
{
this.gameObject.AddComponent<VideoPlayer>();
Player = this.gameObject.GetComponent<VideoPlayer>();
_Download();
/*Player.source=VideoSource.VideoClip;
Player.clip = clip;
Player.Prepare();*/
// Player.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
}
// Update is called once per frame
void Update() {
if (!Player.isPlaying && Player.isPrepared)
{
Player.Play();
}
}
private IEnumerator WaitForDownload(string sURL)
{
Url = new WWW(sURL);
//WWW www = new WWW(sURL);
Debug.Log(Url.bytesDownloaded);
yield return Url;
if (Url.isDone)
{
Debug.Log("Player ready");
Invoke("PlayVideo",20f);
}
else
{
Debug.Log(Url.bytesDownloaded);
}
yield return Url;
}
private void _Download()
{
try
{
StartCoroutine(WaitForDownload("http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4"));
// return Url.bytes;
}
catch(Exception e)
{
Debug.Log(e.ToString());
}
}
public void PlayVideo()
{
Debug.Log("url download complete");
File.WriteAllBytes(Application.dataPath + "/Resources"+"/bunny.mp4", Url.bytes);
clip =(VideoClip) Resources.Load("bunny.mp4");
Player.source=VideoSource.VideoClip;
Player.clip = clip;
test = 5.0f;
// Player.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
if (Player.isPrepared)
{
Player.Play();
}
}
}
這是檢查器面板在運行時的屏幕截圖。
我在腳本中添加了一個測試變量來驗證如果有什麼在運行時獲得或沒有更新。因此,檢查器面板中的測試變量的值會更新,但視頻剪輯值不會更新,這就是我的視頻無法播放的原因。
任何解決方案?