1

I was using Meta.Vlc wrapper in a WPF application and I'm doing the migration to LibVLCSharp official library.

With Meta.Vlc I was able to show controls over videoview and with VideoView control of LibVLCSharp it seems that is always on top and doesn't show anything over videoView. For example, following xaml was working well with Meta.Vlc and with LibVLCSharp.WPF doesn't works.

<Grid x:Name="LayoutParent">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="50" />
   </Grid.RowDefinitions>

   <wpf:VideoView
        Grid.Row="0"
        Grid.RowSpan="2"
        x:Name="Player"
        Visibility="Visible">
        <interactivity:Interaction.Behaviors>
            <behaviors:PlayerBehavior />
        </interactivity:Interaction.Behaviors>
    </wpf:VideoView>


   <Canvas x:Name="DrawAreaCamera"
            Grid.Row="0"
            Grid.RowSpan="2"
            Margin="5"
            Visibility="Visible">
        <interactivity:Interaction.Behaviors>
            <behaviors:CameraDrawingBehavior />
        </interactivity:Interaction.Behaviors>
    </Canvas>

    <Border Grid.Row="2"
            Visibility="Visible"
            Background="#2B2B55"
            Padding="5"
            Opacity="0.5" />
    <TextBlock Grid.Row="2"
               VerticalAlignment="Center"
               HorizontalAlignment="Center"
               Visibility="Visible"
               Text="Example"
               FontSize="26"
               Foreground="White" />
</Grid>
JuanDYB
  • 590
  • 3
  • 9
  • 23
  • I don't know about These controls but I'm pretty sure that `LibVLCsharp` is hosting a WinForms control.. see [this](https://stackoverflow.com/questions/5978917/render-wpf-control-on-top-of-windowsformshost).. Hope I'm wrong! – Muhammad Sulaiman Sep 19 '22 at 15:03
  • Thanks for your reply. It seems that `LibVLCsharp.WPF` is creating a new Win32 window: https://github.com/videolan/libvlcsharp/blob/3.x/src/LibVLCSharp.WPF/VideoHwndHost.cs – JuanDYB Sep 19 '22 at 16:02

1 Answers1

2

I have been reading and asking LibVlcSharp community. The key is that LibVlcSharp.WPF control is behind the scenes a WindowsForms Window. This is known as 'Airspace issue' in documentation.

If it's required to put content inside the player you have to put the content inside the control.

Instead of doing like this

<Grid>
    <vlc:VideoView x:Name="VideoView" />
    <Button Click="Play_Clicked">PLAY</Button>
</Grid>

It's neccesary to do in this way.

<Grid>
    <vlc:VideoView x:Name="VideoView">
        <Button Click="Play_Clicked">PLAY</Button>
    </vlc:VideoView>
</Grid>

LibVlcSharp Official Documentation

JuanDYB
  • 590
  • 3
  • 9
  • 23
  • 1
    Just to elaborate a bit : we are indeed embedding a hwnd (like a WindowsFormsHost does) and you can't write WPF content over it, unless you wrap your content in a window and move your window over the control. This is however a hack, and could lead to less-than-ideal behavior, but is a good-enough workaround for most use cases. – cube45 Sep 20 '22 at 22:38
  • 1
    Meta.Vlc does not have this issue because they are not using VLC the same way as we do : they are copying frames in RAM before putting it in an Image object that they switch many times per second. That's what was done in Vlc.DotNet too, but is known to be CPU-intensive, and we decided not to go that way with LibVLCSharp, and use hardware acceleration all the way down (the frames do not leave the GPU, as it uses DirectX to show the frames) – cube45 Sep 20 '22 at 22:41
  • Thanks for clariying my answer. Yes, I have been reading the Meta.Vlc code and it is working as Image control using ImageSource object to show frames. Also they are using this method to save images and doint Snapshots. But, at the moment those alternatives are deprecated and I think that's better to migrate to LibVlcSharp (in my opinion) – JuanDYB Sep 21 '22 at 21:07