WPF之VLC流媒体播放

时间:2022-04-19 06:01:49

最近在做关于在WPF使用VLC流媒体播放的问题,现在可以在WPF中实现VLC本地播放了,流播放解决了,在下面的代码中注释流媒体播放那两段代码,更多的在乎大家摸索了^^,以供大家相互学习,这里我就先把实现VLC本地播放的代码和过程写给需要的朋友参考。

一、首先到下面网站:

http://vlcdotnet.codeplex.com/releases/view/77778

下载

WPF之VLC流媒体播放 VideoLan DotNet for WinForm, WPF, SL5 - 2011.11.29.zip

然后解压后里面有五个.dll

1.Vlc.DotNet.Core.dll
2.Vlc.DotNet.Core.Interops.dll
3.Vlc.DotNet.Forms.dll
4.Vlc.DotNet.Silverlight.dll
5.Vlc.DotNet.Wpf.dll

根据你做的程序是用什么写的来添加不同的引用,例如:你使用WPF来做的程序就选择Vlc.DotNet.Wpf.dllVlc.DotNet.Core.dll、Vlc.DotNet.Core.Interops.dll添加到项目中并引用。

二、在VLC官网下载最新的VLC播放器,然后安装,安装后在安装文件目录中分别把文件VideoLAN\VLC\和VideoLAN\VLC\plugins\拷贝到项目中。

完成以上任务后在XAML中添加命名空间的引用:

xmlns:local="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"

<Grid>

<Image x:Name="img"/>

<Grid/>

然后在项目中的后台代码如下:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
var appPath = AppDomain.CurrentDomain.BaseDirectory;
VlcContext.LibVlcDllsPath = appPath + @"VLC\";
//Set the vlc plugins directory path
VlcContext.LibVlcPluginsPath = appPath + @"plugins\";

//Set the startup options
VlcContext.StartupOptions.IgnoreConfig = true;
VlcContext.StartupOptions.LogOptions.LogInFile = false;
VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = false;
VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.None;

//Initialize the VlcContext
VlcContext.Initialize();

VlcControl myVlcControl = new VlcControl();
// 创建绑定,绑定Image
Binding bing = new Binding();
bing.Source = myVlcControl;
bing.Path = new PropertyPath("VideoSource");
img.SetBinding(Image.SourceProperty, bing);

//流媒体播放

var media=new LocationMedia("udp://@:ip:port");

myVlcControl.Play(media);

//本地播放

myVlcControl.Play(new PathMedia(添加本地视频路径));

//VlcContext.CloseAll();
}

如果各位有什么疑问或者更好的建议请多多指教!Thanks!!!