zoukankan      html  css  js  c++  java
  • 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, @"..\..\..\lib\x86\"));
    else
    e.VlcLibDirectory = new DirectoryInfo(System.IO.Path.Combine(currentDirectory, "libvlc","x64"));
    }
    }

     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连接

  • 相关阅读:
    Flink 1.14 新特性预览
    基于 MaxCompute 的实时数据处理实践
    Serverless 工程实践 | 细数 Serverless 的配套服务
    不得不看!虚拟货币和区块链的关系
    美国华尔街拥抱区块链是最大的威胁
    1.图片底部圆弧
    二、快捷键
    三、ASP.NET Core 部署Linux
    一、.NET Core MVC 项目结构模板
    一、纯css实现顶部进度条随滚动条滚动
  • 原文地址:https://www.cnblogs.com/javalinux/p/14547558.html
Copyright © 2011-2022 走看看