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

后端 未结 4 1486
予麋鹿
予麋鹿 2021-02-12 12:21

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 t

4条回答
  •  孤街浪徒
    2021-02-12 13:10

    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&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&showinfo=0");
            }
    
        }
    }
    

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

提交回复
热议问题