最近在做關於在WPF使用VLC流媒體播放的問題,現在可以在WPF中實現VLC本地播放了,流播放解決了,在下面的代碼中注釋流媒體播放那兩段代碼,更多的在乎大家摸索了^^,以供大家相互學習,這裡我就先把實現VLC本地播放的代碼和過程寫給需要的朋友參考。
一、首先到下面網站:
http://vlcdotnet.codeplex.com/releases/view/77778
下載
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.dll、Vlc.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!!!