C# 在你的 winforms 中嵌入 youtube/videos

C# embed youtube/videos in your winforms(C# 在你的 winforms 中嵌入 youtube/videos)
本文介绍了C# 在你的 winforms 中嵌入 youtube/videos的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个问题,我在 winform 中添加了冲击波播放器.但似乎youtube不再支持它了.那么如何将视频/youtube 视频嵌入到我的 winform 应用程序中?

解决方案

您可以使用

注意

  1. 您应该确保使用正确的网址.例如,对于您可以在以下地址看到的视频:https://www.youtube.com/watch?v=L6ZgzJKfERM,嵌入 url 为 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# 在你的 winforms 中嵌入 youtube/videos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

ActiveDirectory error 0x8000500c when traversing properties(遍历属性时 ActiveDirectory 错误 0x8000500c)
search by samaccountname with wildcards(使用通配符按 samaccountname 搜索)
Get the list of Groups for the given UserPrincipal(获取给定 UserPrincipal 的组列表)
Can you find an Active Directory User#39;s Primary Group in C#?(你能在 C# 中找到 Active Directory 用户的主要组吗?)
How to register System.DirectoryServices for use in SQL CLR User Functions?(如何注册 System.DirectoryServices 以在 SQL CLR 用户函数中使用?)
Query From LDAP for User Groups(从 LDAP 查询用户组)