zoukankan      html  css  js  c++  java
  • 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 (可选)

    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 "libvlcwin-x86" and "libvlcwin-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(@".libvlcwin-x86"));
                else
                    e.VlcLibDirectory = new DirectoryInfo(Path.GetFullPath(@".libvlcwin-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

  • 相关阅读:
    Python 日期格式化 及 schwartzian排序
    好的数据源
    董的博客 hadoop
    hadoop 2.2.0 集群部署 坑
    python 单元测试
    减少前端代码耦合
    jQuery $.ajax传递数组的traditional参数传递必须true
    如何做一个大格局的人
    中国各省市县级 JSON 文件
    用v-for进行table循环
  • 原文地址:https://www.cnblogs.com/wintertone/p/10389446.html
Copyright © 2011-2022 走看看