在网络浏览器中嵌入 Youtube 视频.对象不支持属性或方法 [英] Embedding Youtube Videos in webbrowser. Object doesn't support property or method

查看:23
本文介绍了在网络浏览器中嵌入 Youtube 视频.对象不支持属性或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Youtube 最近停止支持以 www.youtube.com/v/{key} 格式嵌入的视频.所以我试图将视频从/v/"转换为/embed/".但是,当我尝试导航到视频时,会弹出以下错误:

我正在使用以下内容导航到网页:

WPF

c#

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

为什么这不能简单地从/v/"切换到/embed/"?我该如何解决这个问题?

解决方案

这是现有 SO 线程的副本

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:

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?

解决方案

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 视频.对象不支持属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆