- Home /
Audio isn't playing when steaming video
Hello all.
I'm in the process of streaming video as it is clogging up my web player. I have it to where the video plays, but the sound isn't playing with it. Do I need to stream the sound separately? Or am I doing something wrong in my code that I currently have written?
Here is the code that I am using:
var url = "";
var www;
var movieTexture;
function Start ()
{
www = new WWW(url);
Debug.Log("Movie Loading..." + url);
movieTexture = www.movie;
while (!movieTexture.isReadyToPlay)
yield;
Debug.Log("Movie Loaded");
}
function OnMouseDown()
{
guiTexture.texture = movieTexture;
transform.localScale = Vector3 (0,0,0);
transform.position = Vector3 (0.5,0.5,0);
guiTexture.pixelInset.xMin = -movieTexture.width / 2;
guiTexture.pixelInset.xMax = movieTexture.width / 2;
guiTexture.pixelInset.yMin = -movieTexture.height / 2;
guiTexture.pixelInset.yMax = movieTexture.height / 2;
audio.clip = movieTexture.audioClip;
movieTexture.Play();
audio.Play();
}
@script RequireComponent(GUITexture)
@script RequireComponent(AudioSource)
The problem may be is that there is no auidio listener.
There is an audio listener. I am basically reworking a script that I had that played audio and video fine. The problem was that video was part of my build, and I am trying to build a web player. I removed all the videos and it took away nearly 70 $$anonymous$$Bs worth of data. So I am trying to get strea$$anonymous$$g to work, as that gets me in the ballpark of a good web player size.
I updated my original post to show a new script I am using. Still though, no sound plays when the video is strea$$anonymous$$g. Anyone have any thoughts as to what it might be?
Answer by tylo · Dec 02, 2011 at 02:37 AM
This script works for me for playing Audio & Video, and then changing to Level 1 when the video is done playing.
using UnityEngine; using System.Collections;
public class VideoStream : MonoBehaviour {
WWW wwwData;
public string url;
// Use this for initialization
IEnumerator Start () {
wwwData = new WWW(url);
m = wwwData.movie;
while(!m.isReadyToPlay)
yield return null;
guiTexture.texture = m;
transform.localScale = new Vector3 (0,0,0);
transform.position = new Vector3 (0.5f,0.5f,0);
Rect temp = guiTexture.pixelInset;
temp.xMin = -m.width / 2;
temp.xMax = m.width / 2;
temp.yMin = -m.height / 2;
temp.yMax = m.height / 2;
guiTexture.pixelInset = temp;
audio.clip = m.audioClip;
yield return StartCoroutine(Play());
}
IEnumerator Play(){
m.Play();
audio.Play();
while(current < m.duration){
current += Time.deltaTime;
yield return null;
}
Application.LoadLevel(1);
}
MovieTexture m;
float current;
}
Answer by jhonmiller · May 21, 2012 at 11:29 AM
I'm having same sort of problem and the answer I explore here seems to me effective. Hopefully by following these ways audio playing difficulty will be fixed. Thanks link text