gpt4 book ai didi

c# - 在网络浏览器中嵌入 Youtube 视频。对象不支持属性或方法

转载 作者:IT王子 更新时间:2023-10-29 04:44:14 29 4
gpt4 key购买 nike

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

enter image description here

enter image description here

enter image description here

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

WPF

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

c#

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

为什么仅通过从“/v/”切换到“/embed/”就无法工作?我该如何解决这个问题?

最佳答案

这是现有 SO 线程的副本

Use latest version of Internet Explorer in the webbrowser control

线程中有很多答案以及实际代码。

最好的建议是在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION 中为您的 app.exe 设置一个非常高的数字>

我将它设置为 20000,这可以安全地假设在许多即将到来的版本中工作并使用最新版本。这种情况在您的 exe 设置过程中很容易完成。因此,您不必担心哪个版本存在,哪个不存在。嵌入工作所需的最低版本是 IE 9。

此外,另一种选择是根本不使用嵌入式 IE。相反,请使用 Chromium。在

上有一个相同的 CefSharp 项目

https://cefsharp.github.io/

此项目允许您在 WinForms 或 WPF 应用程序中嵌入 Chromium 浏览器。该应用程序非常简单

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");
}

}
}

而且效果很好。这将使您的应用程序不依赖于目标计算机上安装的浏览器。

Youtube Chromium

关于c# - 在网络浏览器中嵌入 Youtube 视频。对象不支持属性或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46185600/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com