Reputation: 1243
I am developing a lightweight desktop application in C#.NET (Windows Forms) on Windows 7 64-bit that can search and play YouTube videos.
I have spent the entire night and day trying to make the app play videos in all possible manners (I've tried WebBrowser and Shockwave ActiveX Control), and I haven't been able to play any video within the app, except if I force WebBrowser to navigate to the full YouTube video page through the URL https://www.youtube.com/watch?v={VIDEO_ID}.
What I actually want is to be able to embed only the player itself in the WebBrowser, not the entire YT video page. Here is what I have tried so far:
Does work, but is not what I need:
WebBrowser.Navigate("https://www.youtube.com/watch?v=" + video.Id);
Does not work:
WebBrowser.Navigate("https://www.youtube.com/embed/" + video.Id);
Browser.Navigate("about:blank");
Browser.Document.OpenNew(true);
Browser.DocumentText =
"<html><body>" +
"<iframe width='420' height='315' src='https://www.youtube.com/embed/" + video.Id + "&html5=1' frameborder='0' allowfullscreen></iframe>" +
"</body></html>";
Browser.DocumentText =
"<object width='640' height='390'>" +
"<param name='movie' value='https://www.youtube.com/v/" + video.Id + "?version=3&autoplay=1'></param>" +
"<param name='allowScriptAccess' value='always'></param>" +
"<embed src='https://www.youtube.com/v/" + video.Id + "?version=3&autoplay=1' " +
"type='application/x-shockwave-flash' allowscriptaccess='always' width='640' height='390'></embed>" +
"</object>";
AxShockwaveCtl.GotoMovie("https://www.youtube.com/v/" + video.Id);
AxShockwaveCtl.Play();
AxVideo.SRC = "https://www.youtube.com/v/" + video.Id;
AxVideo.swURL = "https://www.youtube.com/v/" + video.Id;
AxVideo.Play();
I believe I tried other stuff like WebBrowser.Document.Write as well, but nothing works. I have seen other questions here about this issue but they all seem to fix their problem in the end somehow, and I've tried to do what they did but in my case nothing works. Also tried changing all Internet Explorer settings. Everything works when I am on a "full" browser like IE 11 or Chrome, but my application just displays a black rectangle where the YouTube video should be.
Upvotes: 1
Views: 4423
Reputation: 2477
The problem comes from the latest windows update. Can not tell where the problem lies in, but the fault lies in the flash component.
So if you forces the youtube video in html5 mode it should work. Try following
WebBrowser.Navigate("https://www.youtube.com/embed/" + video.Id + "?html5=1");
Upvotes: 1