简体   繁体   English

如何阻止 Grid 控件中的 VideoView 控件使用 LibVLCSharp 库打开新的 window?

[英]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.

相关问题 AvaloniaUI:无法在 UserControl 中嵌入 VideoView 控件 (LibVlcSharp) - AvaloniaUI: Cannot embed VideoView control (LibVlcSharp) in a UserControl 如何在WPF中打开新用户控件而不打开新窗口? - How to load a new user control without opening a new window in WPF? 如何使用C#将WPF用户控件库添加到WPF窗口 - How do I add a WPF User Control Library using C# to a WPF window 如何在 LibVLCSharp 中控制音频音高偏移? - How to control audio pitch-shift in LibVLCSharp? 如何阻止 webview2 打开新浏览器 window 而不是在浏览器内部 - How to stop webview2 from opening new browser window rather than inside the browser 当单元格使用RepositoryTextEditor时,如何从网格上的单元格中移走控制权 - How do I take control away from a cell on a grid when the cell is using a RepositoryTextEditor 如何从用户控件里面关闭一个窗口? - How to close a window from the user control inside? 在 window 内的用户控件内打开新对话框的最佳做法是什么? - What is the best practice for opening a new dialog inside a user control inside a window? 如何从主窗口在WPF中调用用户控件? - How do i call user control in WPF from main window? 当我使用Designer向表单添加新控件时,如何阻止visual studio更改WPF表单中控件的属性? - How to stop visual studio from changing properties of controls in WPF form when I add a new control to form using Designer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM