zoukankan      html  css  js  c++  java
  • WPF VlC 实现视频的播放(1)

    WPF 使用VLC实现视频的播放:网上开源代码我复制了一份:  https://github.com/someonehan/Vlc.DotNet

    1. 准备阶段

        (I)  libvlc.dll 和 libvlccore.dll 是必须的两个库

        (II) 配合使用和还要有plugins文件夹下面的乱七八糟的dll,这个东西如果不好找可以在电脑上安装一个vlc播放器然后在安装目录下面就能够找到这个文件夹

    2. 使用播放

        (I) 在使用这个开源的控件之前需要指定VlcLibDirectory其实主要就是plugins文件夹下面乱七八糟的dll(这里面肯定有好多东西是没有用的)指定这个VlcLibDirectory我使用这两种方法:

                var currentAssembly = Assembly.GetEntryAssembly();
                var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
                vlcControl.MediaPlayer.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"......libx64"));
    View Code
    vlcControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
    
            private void OnVlcControlNeedsLibDirectory(object sender, Forms.VlcLibDirectoryNeededEventArgs e)
            {
                var currentAssembly = Assembly.GetEntryAssembly();
                var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
                if (currentDirectory == null)
                    return;
                if (AssemblyName.GetAssemblyName(currentAssembly.Location).ProcessorArchitecture == ProcessorArchitecture.X86)
                    e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"......libx86"));
                else
                    e.VlcLibDirectory = new DirectoryInfo(Path.Combine(currentDirectory, @"......libx64"));
            }
    View Code

    毫无疑问第二种方法要好许多,第一种方式是我在我的电脑上运行使用的。

       (II)  vlcControl是个什么东西啊,这个是我们需要在xmlns界面上定义的开源代码中定义好的控件

    xmlns:wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
    <--!这个引用是必须要加上的 -->
    <wpf:VlcControl x:Name="vlcControl"></wpf:VlcControl>
    View Code

       (III) 剩下的就是播放视频了,我们可以在适当的时候调用类似下面的代码,当然给予Vlc强大的功能我们不仅可以播放任何格式的本地视频(擦,现在各种格式的视频格式真是让人蛋疼了)还可以播放网络视频

    vlcControl.MediaPlayer.Play(new FileInfo(@"C:UsersPublicVideosSample VideosWildlife.wmv"));//播放咱们电脑上都有的野生动物的视频
    View Code

    下面这个是我在网上找的一段新闻视频

    vlcControl.MediaPlayer.Play(new Uri("http://218.93.204.74/145/49/102/letv-uts/14/ver_00_22-322571901-avc-479655-aac-32005-220400-14345429-51c2a04560d147a24c1357f68cd84849-1436438909790_mp4/ver_00_22_3_3_1_820432_700112.ts?crypt=30aa7f2e236&b=520&nlh=3072&nlt=45&bf=36&p2p=1&video_type=mp4&termid=1&tss=ios&geo=CN-1-12-1&platid=1&splatid=101&its=0&proxy=3736741834,987235498,1032384108&keyitem=platid,splatid,its&ntm=1436767800&nkey=d0d58ef311bc08d22da3b6d753a97c31&nkey2=1a2c44f168e70910f6586dcd1dba9217&mltag=1&mmsid=32925199&tm=1436756751&key=ed30d40ea485ed2ea14d0a2b17f71c6b&playid=0&vtype=13&cvid=474368485029&payff=0&ctv=pc&m3v=1&hwtype=un&ostype=WindowsServer2008R2&tag=letv&sign=zw_baidushort&p1=1&p2=10&p3=-&tn=0.11052118893712759&pay=0&uuid=E98B6E3090FB295CF7C5E1030BAF7F351C1F96A6&token=null&uid=null&rateid=1000&errc=0&gn=1058&buss=100&qos=4&cips=113.208.137.58&ch=&p1=1&p2=10&p3=-&appid=500&v=vod.4.2.07022222&rd=1436756767540"));
    View Code

    简单的播放先实现在这,如果要播放共享内存中的视频应该怎么弄?暂时我还不知道找时间好好看看!

  • 相关阅读:
    WinAPI: ExtTextOut 扩展的文本输出
    WinAPI: SetTextCharacterExtra 设置字符间距
    WinAPI: DrawTextEx 多功能文本绘制
    WinAPI: sndPlaySound 播放 wav 文件
    WinAPI: SetTextColor 设置设备环境的文本颜色
    WinAPI: DrawText 将文本绘制到指定的矩形中
    WinAPI: GetTextColor 获取设备环境的文本颜色
    WinAPI: GetTextAlign 获取绘图环境的文本对齐方式
    ulimit限制之nproc问题
    基于EPOLL写的HTTP服务器(加入了线程池)
  • 原文地址:https://www.cnblogs.com/someoneHan/p/4642800.html
Copyright © 2011-2022 走看看