2015-12-18 21 views
7

URL経由でビデオを読み込もうとしていますが、同じエラーが発生しています。私はUnity 5.3を使用していて、http://docs.unity3d.com/ScriptReference/WWW-movie.html(現在の例はコンパイルされていないため、大幅に変更されています)のサンプルコードを使用しています。WWW経由でムービーを読み込めません

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;である)私はこれに取り組んできました 今のところ、多くのファイルと私のシステムの両方で起こっています。

+1

私はUnity 5.2と5.1を使用してビデオを再生できました。この問題は、最新のバージョンです。 – Alex

+1

ちょっと待つようにしましたか?なぜこのエラーが現れたのか、Unityバグかもしれないが、それが機能の実行を停止しないように見えます。もう少し待つと、ムービーは正常に起動し、音の問題は発生しません( 'pixelInset'が画面の一部に表示されていることを確認してください)。 –

+0

私にとって、実行を停止します。以前のバージョンで作業していたとき、私はオーディオを持っていて、ビデオを見るために設定を微調整しました。 – Alex

答えて

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(); 

iPhoneのファイルシステム。完了したら、ロードして再生することができます。 お手伝いをしてください。

2

解決策が見つかりました。私はunity 5.2.Xと5.3.Xでコードをテストしました。

私はなぜUnity Unityが最初に待ちますか?isDone == trueでダウンロードが完了し、テクスチャのコピーがisReadyToPlay == trueまで待っています。

動画ファイルはOGG形式でなければなりません。動画形式一部のMP4ファイルは動作しません。

コードを確認してください:

using UnityEngine; 
using UnityEngine.UI; 
using System.Collections; 

public class MovieTextureStream : MonoBehaviour { 
    public Text progressGUI; 
    public MeshRenderer targetRender = null; 
    public AudioSource targetAudio = null; 
    public string URLString = "http://unity3d.com/files/docs/sample.ogg"; 
    MovieTexture loadedTexture; 

    IEnumerator Start() { 

     if(targetRender ==null) targetRender = GetComponent<MeshRenderer>(); 
     if(targetAudio ==null) targetAudio = GetComponent<AudioSource>(); 

     WWW www = new WWW (URLString); 
     while (www.isDone == false) { 
      if(progressGUI !=null) progressGUI.text = "Progresso do video: " + (int)(100.0f * www.progress) + "%"; 
      yield return 0; 
     } 

     loadedTexture = www.movie; 
     while (loadedTexture.isReadyToPlay == false) { 
      yield return 0; 
     } 
     targetRender.material.mainTexture = loadedTexture; 
     targetAudio.clip = loadedTexture.audioClip; 
     targetAudio.Play(); 
     loadedTexture.Play(); 
    } 
} 
+0

あなたのコードをword-for-wordで試してみましたが、 'loadedTexture = www.movi​​e;'という行に同じエラーが表示されていました - 読み込みエラー:エラー:リソース(null) 、(無効なパラメータがこの関数に渡されました) UnityEngine.WWW:get_movie()。このスクリプトと同じオブジェクトにコンポーネントが添付されていますか、それとも何か不足している可能性がありますか? –

+0

Unity 5.3.1このエラーは実際には警告です。あなたのプロジェクトをコンパイルすると完璧に動作します。たぶんUnity 3D EDITORのバグだけかもしれません。 –

+0

別の重要なことは、このコードを添付しているオブジェクトにオーディオソースとメッシュレンダリングを添付する必要があることです。 –

関連する問題