Skip to content

Improved Avalonia Sample Hack#421

Open
nunofaria007 wants to merge 1 commit intovideolan:3.xfrom
nunofaria007:avalonia-videoview-improvedhack
Open

Improved Avalonia Sample Hack#421
nunofaria007 wants to merge 1 commit intovideolan:3.xfrom
nunofaria007:avalonia-videoview-improvedhack

Conversation

@nunofaria007
Copy link
Copy Markdown

@nunofaria007 nunofaria007 commented Apr 6, 2026

Improved the previous LibVLCSharp.Avalonia.Samples VideoPlayer hack and made it more reusable.

Description of Change

-Transformed VideoPlayer into a more reusable component with it's own MediaPlayer DirectProperty that takes ownership of VideoView.MediaPlayerProperty (...but does taking ownership even matter!?)
-The .axml now defines a ControlTemplate where VideoView's MediaPlayer and Content are TemplateBinded
-Removed any reference to a ViewModel in the VideoPlayer
-Now it is possible to set the overlay directly on VideoPlayer instead of VideoView

<Window>
   <VideoPlayer {Binding MediaPlayer}>
       <Panel> <- we can use the top level container to handle pointer events
           ...some other controls
       </Panel>
   </VideoPlayer>
</Window>

Note: VideoPlayer pointer events don't trigger, but we can wire them like this if really needed:

VideoPlayer.axml:

 <vlc:VideoView Content="{TemplateBinding Content}"
                           PointerEntered="VideoView_PointerEvent"
                           ...any other event needed
                           MediaPlayer="{TemplateBinding MediaPlayer}"/>

VideoPlayer.axml.cs:

private void VideoView_PointerEvent(object? sender, PointerEventArgs e)
{
    this.RaiseEvent(e);
}

This could also be integrated into the library:

-VideoPlayer would become the new VideoView
-The old VideoView would become NativeVideoView

Issues Resolved

None

API Changes

None

Platforms Affected

None

Behavioral/Visual Changes

None

Before/After Screenshots

Not applicable

Testing Procedure

PR Checklist

  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

Improved the previous VideoPlayer UserControl hack and made it more reusable.
@mfkl
Copy link
Copy Markdown
Member

mfkl commented Apr 7, 2026

Hi,

Thanks for the PR.

I'm not sure about this change though. The idea of this sample is to show a minimal implementation of the VideoView and keep it as simple and straightforward as possible. Real apps can build on this and add their own abstractions, but it's sort of out of scope for this repo. We have more complete samples here https://github.com//mfkl/libvlcsharp-samples if you'd like to contribute a more featured avalonia mediaplayer sample.

Additionally, your code removes the autoplay functionality and the controls overlay on hover.

Media URL indeed seems to be invalid, and it could be updated for all samples.

@nunofaria007
Copy link
Copy Markdown
Author

Hi,

Originally i meant to submit the UserControl as part of the library and rework the sample too. Instead I took a simpler approach and changed the sample just to showcase the Control and let you decide if it would be worth to integrate it in the library. For the end-user it would mean having a straightforward Control without having to reproduce the hack seen in the sample just to keep the video from popping out of the window.

"Additionally, your code removes the autoplay functionality and the controls overlay on hover." - true, I was not sure what would be better, if letting the control trigger those events, or if letting the child control do it, so I ended up just commenting the code for reference. In my personal project I was handling the events through the child, but now on second thought others might want to access to those events without having to add a child, so it would make sense to wire them up.

Other thing I noticed. When pressing F12 to use the DevTools we can't inspect the children of VideoView, only way around is calling AttachDevTools programatically then pressing F12. This will cause the extra Window to be listed. With the UserControl I provided this behavior changes. Pressing F12 immediately shows the child element in the MainWindow hierarchy. Calling AttachDevTools and pressing F12 will make the extra Window to be listed, but the hierarchy of MainWindow remains the same.

Old sample F12 - ControlsPanel doesn't show up
old sample F12

Old sample AttachDevTools + F12 - ControlsPanel shows up under Window
old sample AttachDevTools + F12

New sample F12 - ControlsPanel show up under VideoPlayer
new sample F12

New sample AttachDevTools + F12 - ControlsPanel show up under VideoPlayer and under Window
new sample AttachDevTools + F12

@mfkl
Copy link
Copy Markdown
Member

mfkl commented Apr 8, 2026

Ok I can see how having F12 could be helpful but I also try to limit unnecessary breaking changes. UserControl support was added in 8a5257b which could indeed be a nicer user experience if we provide it out of the box. Could this be done without breaking the existing VideoView API tho?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants