我试图通过Vlc.DotNet在WPF中使用VLC。我成功地让Vlc.DotNet在Winforms中工作,但迄今为止WPF都没有成功。
我没有错误,但我也没有视频......只是一个空白的白色窗格。
这是我非常简单的XAML:
<Window x:Class="VLC.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Closing="Window_Closing">
<Grid x:Name="Grid1">
</Grid>
</Window>
这是我用来插入和启动Vlc Wpf控件的代码隐藏。
public MainWindow()
{
VlcContext.LibVlcDllsPath = CommonStrings.LIBVLC_DLLS_PATH_DEFAULT_VALUE_AMD64;
VlcContext.LibVlcPluginsPath = CommonStrings.PLUGINS_PATH_DEFAULT_VALUE_AMD64;
VlcContext.StartupOptions.IgnoreConfig = true;
VlcContext.Initialize();
InitializeComponent();
var vlcPlayer = new VlcControl();
var media = new LocationMedia("rtsp://admin:12345@192.168.42.200:554/MediaInput/h264");
Grid1.Children.Add(vlcPlayer);
var vlcBinding = new Binding("VideoSource");
vlcBinding.Source = vlcPlayer;
var vImage = new Image();
vImage.SetBinding(Image.SourceProperty, vlcBinding);
var vBrush = new VisualBrush();
vBrush.TileMode = TileMode.None;
vBrush.Stretch = Stretch.Uniform;
vBrush.Visual = vImage;
Grid1.Background = vBrush;
vlcPlayer.Play();
}
有人看到这个有什么问题吗?
使用Vlc 2.1.5 win32
答案 0 :(得分:1)
您尚未设置vlcPlayer的Media property
。
var vlcPlayer = new VlcControl();
var media = new LocationMedia("rtsp://admin:12345@192.168.42.200:554/MediaInput/h264");
vlcPlayer.Media = media; //add this
顺便说一下,您无需将vlcPlayer
添加到Grid1
。