[英]How do I stop VideoView control inside a Grid control from opening a new window using LibVLCSharp library?
I'm using the LibVLCSharp.WPF
to play a video using the VideoView
control.我正在使用LibVLCSharp.WPF
使用VideoView
控件播放视频。 I've binded MediaPlayer and Visibility in my ViewModel
.我在ViewModel
中绑定了 MediaPlayer 和 Visibility 。 I can get it to play the video but rather than be embedded inside the Grid control it creates and opens a new window and plays the video there.我可以让它播放视频,而不是嵌入到它创建的网格控件中,并打开一个新的 window 并在那里播放视频。 I've searched and saw there is an airspace issue but maybe there is something I'm doing wrong to keep the video from playing inside the grid like when you place an image in an image control.我已经搜索并看到存在空域问题,但也许我做错了一些事情,以防止视频在网格内播放,就像将图像放在图像控件中时一样。
The player is inside a UserControl that is inside the MainWindow.播放器位于 MainWindow 内的 UserControl 中。
XAML XAML
<Grid>
<media:VideoView x:Name="MediaPlayer"
VerticalAlignment="Center"
HorizontalAlignment="Center"
MediaPlayer="{Binding MyMediaPlayer}"
Visibility="{Binding IsMediaPlayerVisible, Converter={StaticResource VisConverter}}"/>
</Grid>
ViewModel视图模型
void StartVideo()
{
IsMediaPlayerVisible = true;
Core.Initialize();
using (_libVLC = new LibVLC())
{
MyMediaPlayer = new MediaPlayer(_libVLC);
MyMediaPlayer.Media = new Media(_libVLC, new Uri(@"path\to\media\file"));
MyMediaPlayer.Play();
}
}
Can I embed the VideoView
like a Image control inside a Grid?我可以像网格中的图像控件一样嵌入VideoView
吗?
Please always share a full minimal sample.请始终分享完整的最小样本。 Your Q is missing most of the code.您的 Q 缺少大部分代码。
LibVLC will create a new Windows when the Window provided (eg the VideoView here) isn't ready or fully initialized.当提供的 Window(例如此处的 VideoView)未准备好或未完全初始化时,LibVLC 将创建一个新的 Windows。
As a rule of thumb, always start with the official libvlcsharp samples.根据经验,总是从官方的 libvlcsharp 示例开始。 https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/samples/LibVLCSharp.WPF.Sample/Controls.xaml.cs https://code.videolan.org/videolan/LibVLCSharp/-/blob/3.x/samples/LibVLCSharp.WPF.Sample/Controls.Z44CC44B81911F4BA4581C72
public Controls(Example1 Parent)
{
parent = Parent;
InitializeComponent();
// we need the VideoView to be fully loaded before setting a MediaPlayer on it.
parent.VideoView.Loaded += VideoView_Loaded;
PlayButton.Click += PlayButton_Click;
StopButton.Click += StopButton_Click;
Unloaded += Controls_Unloaded;
}
private void VideoView_Loaded(object sender, RoutedEventArgs e)
{
_libVLC = new LibVLC(enableDebugLogs: true);
_mediaPlayer = new MediaPlayer(_libVLC);
parent.VideoView.MediaPlayer = _mediaPlayer;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.