如何在 WPF 中使用 Vlc.DotNet?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27574131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Vlc.DotNet in WPF?
提问by davecove
I am trying to use VLC in WPF via Vlc.DotNet. I have been successful in getting Vlc.DotNet to work in Winforms, but thus far unsuccessful with WPF.
我正在尝试通过 Vlc.DotNet 在 WPF 中使用 VLC。我已经成功地让 Vlc.DotNet 在 Winforms 中工作,但到目前为止没有成功使用 WPF。
I get no errors, but I also get no video... just a blank white pane.
我没有收到任何错误,但我也没有收到视频……只是一个空白的白色窗格。
Here is my very simple XAML:
这是我非常简单的 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>
And here is the codebehind I use to insert and start the Vlc Wpf control.
这是我用来插入和启动 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:[email protected]: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();
}
Does anyone see anything wrong with this?
有没有人看到这有什么问题?
Using Vlc 2.1.5 win32
使用 Vlc 2.1.5 win32
回答by kennyzx
You haven't set vlcPlayer's Media property.
你还没有设置 vlcPlayer 的Media property.
var vlcPlayer = new VlcControl();
var media = new LocationMedia("rtsp://admin:[email protected]:554/MediaInput/h264");
vlcPlayer.Media = media; //add this
Btw, you don't need to add vlcPlayerto Grid1.
顺便说一句,您不需要添加vlcPlayer到Grid1.

