x


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)
more ▼

asked Oct 27 '11 at 03:58 PM

dibonaj gravatar image

dibonaj
233 13 17 17

The problem may be is that there is no auidio listener.

Oct 27 '11 at 09:19 PM Ampler Games

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 MBs worth of data. So I am trying to get streaming to work, as that gets me in the ballpark of a good web player size.

Oct 27 '11 at 09:28 PM dibonaj

I updated my original post to show a new script I am using. Still though, no sound plays when the video is streaming. Anyone have any thoughts as to what it might be?

Nov 01 '11 at 03:02 PM dibonaj
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
}
more ▼

answered Dec 02 '11 at 02:37 AM

tylo gravatar image

tylo
297 5 9 18

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered May 21 '12 at 11:29 AM

jhonmiller gravatar image

jhonmiller
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x525
x283
x96

asked: Oct 27 '11 at 03:58 PM

Seen: 1654 times

Last Updated: May 21 '12 at 11:29 AM