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();
}
}
}
这是检查器面板在运行时的屏幕截图。
我在脚本中添加了一个测试变量来验证如果有什么在运行时获得或没有更新。因此,检查器面板中的测试变量的值会更新,但视频剪辑值不会更新,这就是我的视频无法播放的原因。
任何解决方案?