Link to home
Start Free TrialLog in
Avatar of starlite551
starlite551Flag for India

asked on

How do I play a YouTube Video in Streaming format using a Windows Forms Application using C#?

I have tried GetResponseStream() method of WebRequest Class.. I am looking for a code using System.Net Namespace..
Avatar of rockiroads
Flag of United States of America image

What about using the web browser control?
Avatar of starlite551


Sorry But I was looking for Non - WPF version of code.. Is there a way to do it using file streams ?? Youtube videos are in .flv format so if we can convert a youtube url into a .flv file then we need some player to play that file.. but its a big procedure and very complex.. I dont think pure c# code can work out on this issue.. Do you have any other suggestion or any idea?? using WebRequest and WebResponse Classes of System.Net namespace we can only extract the html contents of the youtube video page.. how do we extract only video..??
You can generate a small wrapper html page and load it in the web-browser control. The html page would only contain the <object> tag that is used by youtube page to host Flash player plugin.
As for the actual video data, i suggest that you use Wireshark to capture sample video download session and it would tell you the format of the url that the flash player uses to fetch the data. Opening that url and saving data using WebRequest should give you the flv file.
In short, all you need is to figure out the right url to download.
Can You Ellaborate your point.. Can u explain it in code please..? I need the source code for doing it..
This is along the lines of what abmience suggested above:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
	public class Form1 : Form
		private WebBrowser browser;
		private System.ComponentModel.IContainer components = null;

		protected override void Dispose(bool disposing)
			if (disposing && (components != null))

		private void InitializeComponent()
			this.browser = new System.Windows.Forms.WebBrowser();
			// browser
			this.browser.Dock = System.Windows.Forms.DockStyle.Fill;
			this.browser.Location = new System.Drawing.Point(0, 0);
			this.browser.MinimumSize = new System.Drawing.Size(20, 20);
			this.browser.Name = "browser";
			this.browser.Size = new System.Drawing.Size(284, 262);
			this.browser.TabIndex = 0;
			// Form1
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(284, 262);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);


		public Form1()

		private void Form1_Load(object sender, EventArgs e)
			browser.DocumentText =@"<html><head><body>
<object style=""height: 344px; width: 425px""><param name=""movie"" value=""""><param name=""allowFullScreen"" value=""true""><param name=""allowScriptAccess"" value=""always""><embed src="""" type=""application/x-shockwave-flash"" allowfullscreen=""true"" allowScriptAccess=""always"" width=""425"" height=""344""></object>

Open in new window

...note that I just dropped a WebBrowser control named "browser" on my form, then added the code in Form1_Load.
In this example how do u load a different youtube video.. I tried to copy and paste some youtube links in the html code but it didn`t work.. Is there anything special i need to do with the links?
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great this thing works 4 me.. Can we get a list of such Video Ids on You Tube on a ListBox Control? I think it would be a good Idea to populate many Video Ids on a list box control and then play a video which we want by selecting it from the listbox control.. Overall it was a nice experience for me to remember.. Thanks a lot man! :)