I have a problem, i added shockwave player to the winform. But it seems that youtube does not support it anymore. So how can i embed a video/youtube video to my winform application?
Asked
Active
Viewed 1.7k times
7
-
Try using WebBrowser Control, then add the embed code you got from YouTube. I have also seen that VLC Player can play YouTube videos from YouTube url. May be you can get some help from their code. – Sunil Mar 01 '18 at 10:52
-
Already tried, same error. – Mar 01 '18 at 10:53
-
Same error means? What is the error you get? You forgot to added error to your question. – Sunil Mar 01 '18 at 10:55
-
I get something like this: Flash-embedded videos are no longer supported – Mar 01 '18 at 11:03
2 Answers
15
You can use a WebBrowser
control to show embedded youtube video. To do so, put a WebBrowser
control on a form and the put the following code in form:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var embed = "<html><head>"+
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\"/>"+
"</head><body>" +
"<iframe width=\"300\" src=\"{0}\"" +
"frameborder = \"0\" allow = \"autoplay; encrypted-media\" allowfullscreen></iframe>" +
"</body></html>";
var url = "https://www.youtube.com/embed/L6ZgzJKfERM";
this.webBrowser1.DocumentText = string.Format(embed, url);
}
Note
You should make sure you use the correct url. For example for a video that you can see at this address:
https://www.youtube.com/watch?v=L6ZgzJKfERM
, the embed url ishttps://www.youtube.com/embed/L6ZgzJKfERM
.Also you should make sure the video is allowed to be played as embedded. Some videos are just allowed to play on youtube and after you click on play button you receive this error:
This video contains content from XXXXXX. It is restricted from playback on certain sites or applications.

Reza Aghaei
- 120,393
- 18
- 203
- 398
-
-
1
-
-
-
Or even better make the screen only show the video and not the browser. Also does it freeze sometimes for you aswell? – Mar 01 '18 at 12:02
-
For red as backgroupnd color, you should set style for the body: `"" +` – Reza Aghaei Mar 01 '18 at 12:08
-
-
Cheers for the color change, hm it seems that only that particular video freeze. But the audio is still going. – Mar 01 '18 at 12:21
-
To make sure about the solution, you can use the same video which I shared. It's a test video without any audio. – Reza Aghaei Mar 01 '18 at 12:23
-
Well it works perfectly. Any idea how i can stop the video from playing when i switch userControl – Mar 01 '18 at 12:37
-
-
Ah okay i'll try to figure it out. Any idea how to remove white space inside the webrowser without change the background color? i was able to fix the top white space by adding margin: 0, but i still got on the right and bottom of the web control. – Mar 01 '18 at 13:25
-
[It's a WPF answer](https://stackoverflow.com/a/40795036/3110834), but it may help you. – Reza Aghaei Mar 01 '18 at 14:31
-
How do I get the embeded player to fit the webbrowser control fully - so there is no white space? My webbrowser control is already set to fill mode. – tunafish24 Nov 24 '18 at 03:35
0
[// MOST IMPORTANT NOTE :
// c# you have button click you upload video and database
// You show the video using DataList Control inside you use Literal control
// Literal control bind using SqlData Source below link use and bind DataList and Literal Control
Visit https://youtu.be/hXseP_8ZP5I
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;IntegratedSecurity=True;User Instance=True";
cn.Open();
Response.Write("check "+cn.State);
String link = "<iframe width=\"300\" height = \"200\" src = \"https://www.youtube.com/embed/" + TextBox1.Text + "\" frameborder = \"0\" allow = \"autoplay; encrypted-media\" allowfullscreen></iframe>";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Video(VIDEO_DETAILS,PATH)VALUES('"+"YOUTUBE" +"','" + link +"')";
cmd.Connection = cn;
cmd.ExecuteNonQuery();
TextBox1.Text = "";
cn.Close();
}

AJAY KACHHIYAPATEL
- 139
- 2
- 10
-
1While this code snippet may solve the question, [including an explanation](//meta.stackoverflow.com/q/392712/4733879) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Filnor Jul 01 '20 at 08:36