Skip to content

Instantly share code, notes, and snippets.

@col000r

col000r/Test1.cs Secret

Created November 21, 2014 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save col000r/d6361ba2147b2ea454ee to your computer and use it in GitHub Desktop.
Save col000r/d6361ba2147b2ea454ee to your computer and use it in GitHub Desktop.
Unity Video Streaming Example, slightly rewritten
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(AudioSource))]
public class Test1 : MonoBehaviour {
public string url = "http://www.unity3d.com/webplayers/Movie/sample.ogg";
IEnumerator Start () {
// Start download
WWW www = new WWW(url);
// Make sure the movie is ready to start before we start playing
MovieTexture movieTexture = www.movie;
while ( !movieTexture.isReadyToPlay && string.IsNullOrEmpty(www.error) ) {
Debug.Log ( "Waiting... " + www.progress );
yield return null;
}
Debug.Log ("Done waiting! e: " + www.error + ", done? " + www.isDone);
// Assign clip to audio source
// Sync playback with audio
audio.clip = movieTexture.audioClip;
renderer.material.mainTexture = movieTexture;
// Play both movie & sound
movieTexture.Play();
audio.Play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment