URLからビデオ(バニービデオ)をダウンロードし、ビデオプレーヤーコンポーネントを使用して再生しようとしています。UnityのVideoPlayerを使用してURLからダウンロードしたビデオクリップを再生できません
私がここで問題になっているのは、エディタモードでビデオプレーヤーにダウンロード済みのクリップまたはURLを渡すと、問題なくビデオが再生されますが、VideoPlayerコンポーネントを自分のゲームオブジェクトに動的に追加して、ビデオプレーヤーには、決してビデオを再生しません。クリップオプションは、再生モードで常にVideoPlayerコンポーネントにnullを表示します。また、スクリプトを使って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();
}
}
}
実行時のインスペクタパネルのスクリーンショットです。
私は何が実行時か更新取得しているかどうかを確認するために私のスクリプトでテスト変数を追加しました。テスト変数の値はインスペクタパネルで更新されますが、ビデオクリップの値は更新されないため、ビデオが再生されません。
これにはどのような解決策がありますか?