C#调用VlcControl做一个播放器

C#调用VlcControl做一个播放器

 

开发环境:

Visual Studio 2015

.Net Framework 4.5

1.新建一个Windows窗体应用程序

修改框架为.Net Framework 4.5

 

2.管理NuGet包

下载安装5个包

VideoLAN.LibVLC.Windows(必须)

Vlc.DotNet.Core (可选)

Vlc.DotNet.Core.Interops (可选)

Vlc.DotNet.Forms (必须)

Vlc.DotNet.Wpf (可选)

LibVLCSharp(可选,支持一些扩展功能,如调整视频亮度)

 

3.添加VlcControl

工具箱添加VlcControl,dll位于当前项目中

将VlcControl添加到窗体上

在VlcControl的VlcLibDirectoryNeeded事件中添加如下代码(必须)

复制代码
复制代码
     /// <summary>
        /// Looks for the vlc directory on the opening of the app
        /// Opens a dialog if the libvlc folder is not found for the user to pick the good one
        /// Folder for 32bits should be "libvlc\win-x86\" and "libvlc\win-x64\" for 64 bits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void myVlcControl_VlcLibDirectoryNeeded(object sender, VlcLibDirectoryNeededEventArgs e)
        {
            var currentAssembly = Assembly.GetEntryAssembly();
            var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;

            if (currentDirectory == null)
                return;
            if (IntPtr.Size == 4)
                e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x86\"));
            else
                e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".\libvlc\win-x64\"));

            if (!e.VlcLibDirectory.Exists)
            {
                var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
                folderBrowserDialog.Description = "Select Vlc libraries folder.";
                folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.ShowNewFolderButton = true;
                if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
                {
                    e.VlcLibDirectory = new DirectoryInfo(folderBrowserDialog.SelectedPath);
                }
            }
        }
复制代码
复制代码

4.播放视频

使用VlcControl.Play()方法播放视频

vlcControl1.Play("http://**************/******.flv");//只能播放网络流视频
vlcControl1.SetMedia(new System.IO.FileInfo(@"f:\1.flv"));//本地视频
vlcControl1.Play();

运行结果:


参考:

https://blog.csdn.net/xuehuic/article/details/53914874

https://bbs.csdn.net/topics/390168224

https://cloud.tencent.com/developer/ask/148529

https://github.com/ZeBobo5/Vlc.DotNet/wiki/Using-Vlc.DotNet-in-WinForms

 

posted on   漫思  阅读(6)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
历史上的今天:
2023-02-15 “开源 core-js 也许是我一生中最大的错误”
2023-02-15 如何解决Reporting Services目录数据库文件存在的问题
2023-02-15 怎么处理Reporting Services目录数据库文件存在的问题?
2023-02-15 Redis配置以及通过C#访问小试
2023-02-15 从 Newtonsoft.Json 迁移到 System.Text.Json
2023-02-15 动态Entity Framework查询:Dynamic Query 介绍
2023-02-15 asp.net 开发优秀博客

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示