无法通过WWW加载电影

Ale*_*lex 7 unity-game-engine fmod

我正在尝试通过网址加载视频,但我仍然遇到同样的错误.我正在使用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();

    }

}
Run Code Online (Sandbox Code Playgroud)

我在新场景中将其作为脚本添加到主摄像头,我收到此错误:

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)
Run Code Online (Sandbox Code Playgroud)

(第20行MovieTexture movieTexture = www.movie;)我已经在这方面工作了一段时间,它发生在许多文件和我的两个系统上.

小智 0

我不会提供 WWW.movi​​e 的解决方案,而是提供可能对您或其他任何人有帮助的替代解决方案。在 iPhone 上,我们没有找到从服务器流式传输视频的解决方案,我们决定在阅读之前下载视频,具体方法如下:

string docPath = Application.persistentDataPath + "/" + id + ".mp4";
if (!System.IO.File.Exists(docPath))
{
  WWW www = new WWW(videouUrl);
  while(!www.isDone)
  {
    yield return new WaitForSeconds(1);
    Loading.Instance.Message = "Downloading video : " + (int)(www.progress * 100) + "%";
    if (!string.IsNullOrEmpty(www.error))
      Debug.Log(www.error);
  }
  byte[] data = www.bytes;
  System.IO.File.WriteAllBytes(docPath, data);
}

mediaPlayer.Load(docPath);
onVideoReady();

mediaPlayer.Play();
Run Code Online (Sandbox Code Playgroud)

这是用于下载视频并将其写入 iPhone 文件系统的协程。完成后,您可以加载并播放它。希望能帮助到你。