2017-09-30 9 views
0

ok iveビデオプレイヤーを以前に使用したことがありません。アンドロイドとエディタで動画を再生できますが、オーディオは再生されません。URLからビデオを取得し、ビデオプレーヤーを同じオーディオソースビデオプレーヤーコンポーネントが装着されているように、オブジェクト、IVEはこのリンクUsing new Unity VideoPlayer and VideoClip API to play videoからの助言に従ったがhaventははまだ以下のいずれかの喜びを持っていたイム言及した映像作品が、オーディオdoesntのようにそれを呼び出す方法の順で、誰もがユニティビデオプレーヤーでオーディオが再生されないのはなぜですか?

private AudioSource audio; 
private VideoPlayer screen; 

screen = go.GetComponentInChildren<VideoPlayer>(); 
audio = go.GetComponentInChildren<AudioSource>(); 
audio.playOnAwake = false; 
screen.source = VideoSource.Url; 
screen.url = videoObj.VideoURL; 
screen.audioOutputMode = VideoAudioOutputMode.AudioSource; 
screen.EnableAudioTrack (0,true); 
screen.SetTargetAudioSource (0,audio); 
screen.Prepare(); 
screen.Play(); 
audio.Play(); 

を助けることができます編集

以下のコメントに私はいくつかの情報を追加していますいくつかの点があるので、統一バージョンは2017です。オーディオはエディタやデバイスで再生されませんが、ビデオはエディタやデバイスで正常に動作します。ここではURLはhttps://storage.googleapis.com/godapp-a3e4b.appspot.com/jacopatrolmontage.mp4です。ここでは完全なコードです。私が使用している方法は、私は団結にかなり新しいですし、C#

public void showPlayer(VideoObjects videoObj) 
{ 
    if (GameObject.Find("videoPlaner(Clone)") == null) 
    { 
     //may need scene.isValid 
     GameObject go = Instantiate(videoPlayer); 
     go.transform.SetParent(canvas.transform, false); 
     screen = go.GetComponentInChildren<VideoPlayer>(); 
     audio = go.GetComponentInChildren<AudioSource>(); 
     //audio = go.AddComponent<AudioSource>(); 
     fsscreenBool = true; 
     screenSize = go.GetComponent<Transform>().localScale; 
     screenPosition = go.GetComponent<Transform>().localPosition; 
     canvasRectTransformScale = go.GetComponentInParent<RectTransform> 
     (); 
     foreach (Transform tr in go.transform) 
     { 
      if (tr.gameObject.tag == "play") 
      { 
       Button play = tr.GetComponent<Button>(); 
       AddPlayListener(play, screen); 
       preparePlayer(play,screen.isPlaying); 
      } 
      if (tr.gameObject.tag == "fullscreen") 
      { 
       Button fullScreen = tr.GetComponent<Button>(); 
       AddFSListener(fullScreen, go); 
      } 
      if (tr.gameObject.tag == "forward") 
      { 
      } 
      if (tr.gameObject.tag == "rewind") 
      { 
      } 
      if (tr.gameObject.tag == "vidtitle") 
      { 
       tr.GetComponent<Text>().text = videoObj.VideoTitle; 
      } 
      if (tr.gameObject.tag == "loading") 
      { 
       loading = tr.gameObject; 
      } 
     } 
    } 
    else{ 
     //print("it exists"); 
     GameObject existingGO = GameObject.Find("videoPlaner(Clone)"); 
     screen = existingGO.GetComponentInChildren<VideoPlayer>(); 
     loading.SetActive (true); 
     foreach (Transform tr in existingGO.transform) 
     { 
      if (tr.gameObject.tag == "play") 
      { 
      } 
      if (tr.gameObject.tag == "fullscreen") 
      { 
       checkScreen (existingGO); 
      } 
      if (tr.gameObject.tag == "forward") 
      { 
      } 
      if (tr.gameObject.tag == "rewind") 
      { 
      } 
      if (tr.gameObject.tag == "vidtitle") 
      { 
       tr.GetComponent<Text>().text = videoObj.VideoTitle; 
      } 
      if (tr.gameObject.tag == "loading") 
      { 
      } 
     } 
    } 
    screen.source = VideoSource.Url; 
    screen.url = videoObj.VideoURL; 
    screen.audioOutputMode = VideoAudioOutputMode.AudioSource; 
    screen.EnableAudioTrack (0,true); 
    screen.SetTargetAudioSource (0,audio); 
    screen.Prepare(); 
    audio.Play(); 
    screen.Play(); 
} 
+0

は、あなたがしようとしている動画のURL、完全なコードを投稿しても、Unityのバージョンに言及することはできます。オーディオはエディタで機能しますか? – Programmer

+0

@Programmerが質問を編集して回答に感謝の意を表します – martinseal1987

+1

これを調べる前に、[質問](https://stackoverflow.com/questions/41144054/using-新しいユニティビデオプレイヤーとビデオクリップの両方にリンクしています)それをコピー&ペーストするだけで、 'VideoSource.Url;'部分を変更してURLを追加します。それを再生して、あなたがオーディオを持っているかどうかを確認してください – Programmer

答えて

1

あなたはscreen.Prepare()を呼び出し、それを準備するためにscreen.Play()audio.Play()を呼び出す前に待機していないように私はおそらく間違ってやって離れて他のものを引っ張っていけないしてください。 audio.playOnAwake = false;も設定しましたが、動画には反映されませんでした。また、playOnAwakeでビデオをfalseにする必要があります。動画を再生する前に、動画の読み込み時間を指定します。

screen.Prepare(); 

//Wait until video is prepared 
while (!screen.isPrepared) 
{ 
    yield return null; 
} 

//Assign the Texture from Video to RawImage to be displayed 
image.texture = videoPlayer.texture; 

//Play Video 
screen.Play(); 

//Play Sound 
audio.Play(); 

あなたはそれがすでにMonoBehaviour宣言されている非推奨の変数であるので、何か他のものにあなたのオーディオの変数の名前を変更することもできます。 最後に、をリンクした質問のanswerのコードを使用してください。それはRawImageでビデオを再生できるはずです。

それはまだ、私はUnityは任意のスクリプトで任意のVideoPlayerコードを持っているゲームオブジェクトにRendererを探すことに気づいた私は、重複ビデオ

は一度私に起こっている生の画像と、実際に動作しますそのフレームに添付されたTextureを自動的に更新します。私は彼らがVideoPlayerの使用を簡素化するためにこれをしたと思います。

このスクリプトを空のゲームオブジェクトに添付して、Rendererがない場合は、RawImageをエディタの画像スロットに置くことができます。重複はありません。

0

オーディオが再生されない場合は、screen.prepare()前に次の行を追加します。

videoPlayer.controlledAudioTrackCount = 1; 
関連する問題