C#将youtube /视频嵌入到Winform中 [英] C# embed youtube/videos in your winforms

查看:202
本文介绍了C#将youtube /视频嵌入到Winform中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我在Winform中添加了Shockwave Player。但是,似乎youtube不再支持它。那么如何将视频/ youtube视频嵌入到Winform应用程序中?

解决方案

您可以使用



注意


  1. 您应确保使用正确的网址。例如,对于您可以在以下地址看到的视频: https://www.youtube.com/watch?v=L6ZgzJKfERM ,嵌入网址为 https://www.youtube.com/embed/L6ZgzJKfERM


  2. 此外,您还应确保视频被允许作为嵌入式播放。某些视频只允许在youtube上播放,并且在单击播放按钮后,您会收到此错误:


    该视频包含XXXXXX的内容。仅限
    在某些站点或应用程序上播放。




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

  1. 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 is https://www.youtube.com/embed/L6ZgzJKfERM.

  2. 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.

这篇关于C#将youtube /视频嵌入到Winform中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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