Vlc.DotNet.Wpf,播放rtsp视频,

1.NuGet上下载Vlc.DotNet.Wpf, 在https://github.com/ZeBobo5/Vlc.DotNet 上下载的源码都是最新版本的,里面有调用的示例,每个版本调用方法都不一样。 下面代码以2.2.1为例。

安装完成后,程序中会自动引用相关dll

2. 播放视频相关代码

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>
        <wpf:VlcControl Grid.Row="0" x:Name="myControl" />
        <Button x:Name="btnPlay" Width="120" Height="30" Grid.Row="1" Content="play" />
    </Grid>
 /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            btnPlay.Click += BtnPlay_Click;
            //初始化配置,指定引用库  
            myControl.MediaPlayer.VlcLibDirectoryNeeded += OnVlcControlNeedsLibDirectory;
            myControl.MediaPlayer.EndInit();
        }


        private void BtnPlay_Click(object sender, RoutedEventArgs e)
        {
            //myControl.MediaPlayer.Play(new Uri(AppConfig.rtspUrl));
            myControl.MediaPlayer.Play(new Uri("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"));
            //throw new NotImplementedException();
        }

        private void OnVlcControlNeedsLibDirectory(object sender, Vlc.DotNet.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(System.IO.Path.Combine(currentDirectory, @"......libx86"));
            else
                e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc","x64"));
        }
    }
View Code

 3.替换解码相关dll,代码中是在debug目录下新建libvlc目录,再建x64和x86两个子目录,分别存放相关dll,可以在vlc官网上下载最新exe安装后查找下图中的dll进行存放,这里注意官网上下载的默认的32程序,替换不对的话会出现下面的问题1.

可以找到历史的版本有针对性的下载,如下图。http://download.videolan.org/pub/videolan/vlc/

点击按钮播放后碰到的几个问题。

1.程序出错,不是有效的win32应用程序,原因:把32位的程序dll放到了第三步x64目录下面

2.输出窗口显示 线程已退出,视频无法播放。 这表明解码相关dll没有,注意下第三步重新下载替换。

3.无法找到指定文件,问题是第三步里面的文件有缺失的。

最后再补几个可以测试的地址

http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi

rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov

rtmp://live.hkstv.hk.lxdns.com/live/hks

附带2个demo连接

程序  vlc依赖

原文地址:https://www.cnblogs.com/m7777/p/8487285.html