Web 浏览器控件不播放 YouTube 视频
在 WPF WebBrowser 控件上播放 YouTube 视频时出现新问题
<Window x:Class="plainYoutubeBrowser.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<WebBrowser Name="g_browser"/>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
g_browser.Navigate("http://www.youtube.com/watch?v=y9k-k8609go");
}
}
通常此 URL 在 IE 和其他浏览器中可以正常工作。
问题是,加载页面时视频播放不会自动开始(您将看到一个播放图标,而您必须单击该图标)。
我添加了查询字符串参数&autoplay=1
,但没有帮助。
如何解决这个问题?
There's a new problem playing back YouTube videos on a WPF WebBrowser control
<Window x:Class="plainYoutubeBrowser.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<WebBrowser Name="g_browser"/>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
g_browser.Navigate("http://www.youtube.com/watch?v=y9k-k8609go");
}
}
Normally this URL will work in IE and other browsers without issue.
The problem is that the video playback is not started automatically when the page is loaded (you'll see a play icon instead which you'll have to click on).
I added the querystring parameter &autoplay=1
, but it didn't help.
How can this be solved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许 YouTube javascript/flash 中的某些内容会根据用户代理、引用字段或 DOM 更改其行为。也许它认为它嵌入在 IFrame 中并且不需要自动播放。
我会尝试弄清楚如何通过执行
g_browser.InvokeScript();
来手动触发播放,也许还可以看看是否可以找到一个 URL 来使 youtube 进入 html5 模式并避免使用 flash 。
Perhaps there's something in the YouTube javascript/flash that changes it's behavior based on the user agent, the referrer field, or the DOM. Maybe it thinks it's embedded in an IFrame and that autoplay isn't desired.
I'd try to figure out how to manually trigger the play by doing
g_browser.InvokeScript();
Maybe also see if you can get find a URL to make youtube to go into html5 mode and avoid using flash.