首页 > Windows开发 > 详细

C#调用vlc做一个播放器

时间:2019-02-16 22:37:58      阅读:1559      评论:0      收藏:0      [点我收藏+]

开发环境:

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 

技术分享图片

 

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");

运行结果:

技术分享图片

 

参考:

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

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

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

 

C#调用vlc做一个播放器

原文:https://www.cnblogs.com/wintertone/p/10389446.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!