Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding Youtube Videos in webbrowser. Object doesn't support property or method

Tags:

Youtube has recently stopped supporting videos embedded in the format www.youtube.com/v/{key}. So I was trying to convert the video from "/v/" to "/embed/". However when I try to navigate to the video the following errors then pop up:

enter image description here

enter image description here

enter image description here

I am navigating to the webpage using the following:

WPF

<WebBrowser x:Name="trailer" Margin="655,308,30,135"/>

c#

trailer.Navigate("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0");

Why is this unable to work simply by switching from "/v/" to "/embed/"? And how do I go about resolving this issue?

like image 711
difurious Avatar asked Sep 12 '17 21:09

difurious


People also ask

What happens if you allow embedding on YouTube?

When uploading videos to your channel, you will have the option to allow embedding. Allowing embedding means that people can re-publish your video on their website, blog, or channel, which will help you gain even more exposure.


1 Answers

This is duplicate of an existing SO Thread

Use latest version of Internet Explorer in the webbrowser control

The thread has lots of answers in it with actual code to go with it.

The best suggestion in the same is to set a very high number of for your app.exe in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION

I set it to 20000, which is safe to assume to work in a lot of coming version and to use the latest version as such. This case is easily done during the setup of your exe as such. So you won't have to worry about which version exists and which doesn't. The minimum version you need for embedding to work is IE 9.

Also, another option is not to use Embedded IE at all. Instead, use Chromium. There is a CefSharp project for the same on

https://cefsharp.github.io/

This project allows you to embed chromium browser in your WinForms or WPF app. The app is quite simple

using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        ChromiumWebBrowser chrome;

        private void InitChrome()
        {
            CefSettings settings = new CefSettings();
            Cef.Initialize(settings);
            chrome = new ChromiumWebBrowser("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0");
            this.Controls.Add(chrome);
            chrome.Dock = DockStyle.Fill;
        }
        public Form1()
        {
            InitializeComponent();
            InitChrome();
            //this.webBrowser1.Navigate("https://www.youtube.com/embed/v2fDTOdWuQQ?rel=0&amp;showinfo=0");
        }

    }
}

And works great. This will make your app not be dependent on which browser is installed on the target machine.

Youtube Chromium

like image 117
Tarun Lalwani Avatar answered Sep 17 '22 12:09

Tarun Lalwani