C# - Play a Video from a Webpage

Hello,

I´m trying to play a video from a webpage. I tried to do it with a MovieTexture through creating a plane, giving a guiTexture to it and giving it the following script:

using UnityEngine;
using System.Collections;

public class ViewStream : MonoBehaviour {
	
	GameObject myGameObject;
	
	public WWW wwwData;
    public string url = "http://www.youtube.com/watch?v=tkwwrTW7BQU&feature=g-vrec";
	
	// Use this for initialization
	void Start () {
		wwwData = new WWW(url);
        //guiTexture.texture = wwwData.movie;
		renderer.material.mainTexture = wwwData.movie;
	}
	
	// Update is called once per frame
	void Update () {
		
			
			//MovieTexture m = guiTexture.texture as MovieTexture;
			MovieTexture m = renderer.material.mainTexture as MovieTexture;
			
			if(m.isReadyToPlay==true){
				print ("ready to play");
			}else{
				print ("not ready to play");
			}
			
        	if (!m.isPlaying && m.isReadyToPlay){
            	m.Play();
			}
		
	}
}

First I tried it with the guiTexture. After it didn´t work I tried to use the main material to play it. But this failed also.
In the log is written “not ready to play” all the time.

Can anyone tell me what I´m doing wrong? Does the video file need to have a special format, is my URL not correct or anything else?

Thank you in advance.

Just use the documentation… The example for WWW.movie does what you want.

What you are doing wrong (I am guessing) is YouTube is not giving you an Ogg movie, so it’s never ready to play.

Unity only supports .ogv and .ogg as video and audio format for the web player.

Try this link to download your youtube video as .MP4 http://www.youtubeinmp4.com

and then go to this link to convert and download the video.

http://video.online-convert.com/convert-to-ogg

Have fun!