問題描述
我有一個(gè)問題,我在 winform 中添加了沖擊波播放器.但似乎youtube不再支持它了.那么如何將視頻/youtube 視頻嵌入到我的 winform 應(yīng)用程序中?
您可以使用
注意
您應(yīng)該確保使用正確的網(wǎng)址.例如,對(duì)于您可以在以下地址看到的視頻:
https://www.youtube.com/watch?v=L6ZgzJKfERM
,嵌入 url 為https://www.youtube.com/embed/L6ZgzJKfERM
.此外,您還應(yīng)確保允許以嵌入方式播放視頻.有些視頻只允許在 youtube 上播放,點(diǎn)擊播放按鈕后,您會(huì)收到此錯(cuò)誤:
<塊引用>該視頻包含來自 XXXXXX 的內(nèi)容.它被限制從在某些網(wǎng)站或應(yīng)用程序上播放.
I have a problem, i added shockwave player to the winform. But it seems that youtube does not support it anymore. So how can i embed a video/youtube video to my winform application?
You can use a WebBrowser
control to show embedded youtube video. To do so, put a WebBrowser
control on a form and the put the following code in form:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var embed = "<html><head>"+
"<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>"+
"</head><body>" +
"<iframe width="300" src="{0}"" +
"frameborder = "0" allow = "autoplay; encrypted-media" allowfullscreen></iframe>" +
"</body></html>";
var url = "https://www.youtube.com/embed/L6ZgzJKfERM";
this.webBrowser1.DocumentText = string.Format(embed, url);
}
Note
You should make sure you use the correct url. For example for a video that you can see at this address:
https://www.youtube.com/watch?v=L6ZgzJKfERM
, the embed url ishttps://www.youtube.com/embed/L6ZgzJKfERM
.Also you should make sure the video is allowed to be played as embedded. Some videos are just allowed to play on youtube and after you click on play button you receive this error:
This video contains content from XXXXXX. It is restricted from playback on certain sites or applications.
這篇關(guān)于C# 在你的 winforms 中嵌入 youtube/videos的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!