【发布时间】:2015-12-18 22:14:19
【问题描述】:
我正在尝试通过 url 加载视频,但我不断收到相同的错误。我正在使用 Unity 5.3 和来自 http://docs.unity3d.com/ScriptReference/WWW-movie.html 的示例代码(由于当前示例无法编译而进行了大量修改)。
using UnityEngine;
using System.Collections;
// Make sure we have gui texture and audio source
[RequireComponent (typeof(GUITexture))]
[RequireComponent (typeof(AudioSource))]
public class TestMovie : MonoBehaviour {
string url = "http://www.unity3d.com/webplayers/Movie/sample.ogg";
WWW www;
void Start () {
// Start download
www = new WWW(url);
StartCoroutine(PlayMovie());
}
IEnumerator PlayMovie(){
MovieTexture movieTexture = www.movie;
// Make sure the movie is ready to start before we start playing
while (!movieTexture.isReadyToPlay){
yield return 0;
}
GUITexture gt = gameObject.GetComponent<GUITexture>();
// Initialize gui texture to be 1:1 resolution centered on screen
gt.texture = movieTexture;
transform.localScale = Vector3.zero;
transform.position = new Vector3 (0.5f,0.5f,0f);
// gt.pixelInset.xMin = -movieTexture.width / 2;
// gt.pixelInset.xMax = movieTexture.width / 2;
// gt.pixelInset.yMin = -movieTexture.height / 2;
// gt.pixelInset.yMax = movieTexture.height / 2;
// Assign clip to audio source
// Sync playback with audio
AudioSource aud = gameObject.GetComponent<AudioSource>();
aud.clip = movieTexture.audioClip;
// Play both movie & sound
movieTexture.Play();
aud.Play();
}
}
我将此作为脚本添加到新场景的主摄像机中,但出现此错误:
Error: Cannot create FMOD::Sound instance for resource (null), (An invalid parameter was passed to this function. )
UnityEngine.WWW:get_movie()
<PlayMovie>c__Iterator4:MoveNext() (at Assets/TestMovie.cs:20)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
TestMovie:Start() (at Assets/TestMovie.cs:16)
(第 20 行是 MovieTexture movieTexture = www.movie;)
我已经为此工作了一段时间,它发生在许多文件和我的两个系统上。
【问题讨论】:
-
我已经能够使用 Unity 5.2 和 5.1 播放视频。这是有这个问题的最新版本。
-
您是否尝试过再等一会?我不知道为什么现在出现这个错误,可能是 Unity 错误,但看起来它并没有停止函数执行。如果您稍等片刻,电影将正常开始,并且不会出现声音问题(确保将
pixelInset设置为屏幕的某个可见部分)。 -
对我来说,它确实会停止执行。当它在以前的版本上工作时,我有音频和调整设置来观看视频。
-
您是否在访问 www.movie 之前尝试生成 www 对象?产生一个 www 对象将使协程停止,直到请求的资产下载完成。我不知道电影流的行为会如何,但我会尝试一下。