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连接
标签:
wpf vlc
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?