-
-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic Wpf UserControl #1
Conversation
Added Wpf UserControl with Autosizing using WindowsFormsHost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
/cc @jeremyVignelles
<ProjectGuid>{DA7A2677-0944-481F-A59B-9128FC54FD5F}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>LibVLCSharp.Wpf</RootNamespace> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rename LibVLCSharp.Wpf
to LibVLCSharp.WPF
everywhere please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to wirte Wpf, to case all my namespaces and classes the C# way ( I have tools that complains when I don't)
|
||
namespace LibVLCSharp.Wpf | ||
{ | ||
public partial class VLCViewControl : UserControl, LibVLCSharp.Shared.IVideoView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with the other platforms, can you rename VLCViewControl
with VideoView
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I believe your control needs to be IDisposable
and dispose of libvlc and mediaplayer in the dispose method
LibVlcSharp.Wpf.Sample/App.xaml
Outdated
@@ -0,0 +1,9 @@ | |||
<Application x:Class="LibVlcSharp.Wpf.Sample.App" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename LibVlcSharp.Wpf.Sample
to LibVLCSharp.WPF.Sample
everywhere please.
LibVlcSharp.Wpf.Sample/App.xaml.cs
Outdated
namespace LibVlcSharp.Wpf.Sample | ||
{ | ||
/// <summary> | ||
/// Interaktionslogik für "App.xaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment looks very german :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can rename it of course. Yeah forgot this comment :D
I really wonder if making a wpf control is a good thing. Look at what happened in Vlc.DotNet : Here's the situation now, in Vlc.DotNet :
For the full-length story, see ZeBobo5/Vlc.DotNet#249 With that experience, I would think twice before doing a "Wpf" control. What would you think of having several Wpf implementations? Users would have to read a short readme to take an enlighted decision, but if that could avoid the issues about perfs/about airspace. |
Thanks for the input @jeremyVignelles Unity's dude's take on WPF/D3D situation: sharpdx/SharpDX#599 (comment) TL;DR: "D3DImage is fundamentally broken and unsuitable for efficient D3D rendering in WPF." So right now the choices are:
|
You have no choice here, if you want to target most platforms: Winforms -> airspacing issues. D3DImage does too many copies, and DXGI integration is not working on Windows 7, IIRC, unless people have D3D11 working, which is rare. |
If I remember correctly, WPF is DirectX 9 only. Microsoft provides a
D3D11Image, but it looks like an emulation layer over the D3DImage built
into WPF
Le mer. 4 juil. 2018 à 10:43, Jean-Baptiste Kempf <notifications@github.com>
a écrit :
… You have no choice here, if you want to target most platforms: Winforms ->
airspacing issues.
D3DImage does too many copies, and DXGI integration is not working on
Windows 7, IIRC, unless people have D3D11 working, which is rare.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADPeu8ARpc0C7HhLk2d4w0Sb4mwUHq6Oks5uDIAagaJpZM4VBTeV>
.
|
I know the way VLC.DotNet does this. I thought about DirectX and OpenGL too, but it seems they somehow require Handles too. Even Microsoft wasn't able to fix this - a fix was availible for a short time in PresentationFramework 4.5. Another way mentioned is using Even SharpGL uses Images on WPF EDIT: also in general i know these issues about airspacing, i wrote this to have an basic alternative to Xamarin.Forms, as this works with Wpf without using xamarin |
- Renaming - Disposable
@Ch4rg3r ok, great. My opinion is to use that WPF/Handle and try to fix the airspacing issues. Performance is key! |
@jbkempf i guess that's true. The mentioned way on stackoverflow (no idea if it works) draws the WPF controls on Win32 on top of the WindowsFormsHost and forwards mouse actions to the WPF controls. This way the WPF is copied and drawn twice. Guess that has less performance impact |
I agree with j-b : let's go for the perfs. Thanks @Ch4rg3r for your time and reactivity! Edit : the Vlc.DotNet's airspace issue : |
@jeremyVignelles seems to be the implementation of what i meant, but simpler. And i just tested it. It works, enabling mouse actions for both background and foreground. |
How do you see the interaction with this project? I thought that this would be something to "recommend" for users facing this issue, but not something embedded in the library since most of the users, I guess, just want to display the video, not to hover things on top of that. However I don't know the status of this project (licensing, packaging, support...), and maybe @kolorowezworki can answer that? |
I would make VideoView from it, using the background as MediaPlayer, giving the User of this library the ability to add child elements to the foreground. I guess it requires a few changes |
Now Supports behaviour like container (example Grid). Child Elements can be added in XAML or code behind and will automatically set to foreground Elements (preventing airspace issue)
@Ch4rg3r Let us know when you think this is good for review/testing. |
@mfkl the last change works for me. If you can test it's functionality, please do it. Maybe you find issues or things to be improved. Major issues might be performance. But i cannot say why. Could be the way i use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick GitHub glance. Will build and test later :) Keep up the good work 👍
internal partial class ForegroundWindow : Window | ||
{ | ||
private Window wndhost; | ||
private ContentControl bckgnd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "_" consistently for private fields please.
wndhost.LocationChanged += Wndhost_LocationChanged; | ||
try | ||
{ | ||
Point locationFromScreen = bckgnd.PointToScreen(new Point(0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new Point(0, 0)
allocation can be cached in a readonly field.
System.Windows.Point targetPoints = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen); | ||
this.Left = targetPoints.X; | ||
this.Top = targetPoints.Y; | ||
Vector size = bckgnd.PointToScreen(new Point(bckgnd.ActualWidth, bckgnd.ActualHeight)) - bckgnd.PointToScreen(new Point(0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new Point(0, 0)
allocation can be cached in a readonly field.
} | ||
catch | ||
{ | ||
this.Hide(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe log an error or something? What could possibly happen here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure when this actually can happen. Most likely would only happen, if no Window with Hwnd is provided, but then you wouldn't see anything anyway
|
||
private void Wndhost_LocationChanged(object sender, EventArgs e) | ||
{ | ||
Point locationFromScreen = bckgnd.PointToScreen(new Point(0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new Point(0, 0)
allocation can be cached in a readonly field.
LibVLCSharp.WPF/VideoView.cs
Outdated
if (mediaPlayer.IsPlaying) | ||
mediaPlayer.Stop(); | ||
|
||
mediaPlayer.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may add _mediaPlayer.Hwnd = IntPtr.Zero
LibVLCSharp.WPF/VideoView.cs
Outdated
libVLC = new Shared.LibVLC(); | ||
mediaPlayer = new Shared.MediaPlayer(libVLC); | ||
|
||
this.SizeChanged += OnSizeChanged; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be unregistered in the Dispose method.
LibVLCSharp.WPF/VideoView.cs
Outdated
controlHeight = this.Height; | ||
controlWidth = this.Width; | ||
|
||
this.Loaded += VideoView_Loaded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be unregistered in the Dispose method.
LibVLCSharp/Shared/MediaPlayer.cs
Outdated
@@ -631,6 +631,11 @@ struct Native | |||
#endif | |||
} | |||
|
|||
public void SetVideoFormatCallbacks() | |||
{ | |||
throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea :D i will delete it
|
||
private void StopButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
parent.Dispatcher.Invoke(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off topic/review question: Do you think it'd make sense for the binding to offer a dispatcher callback registration, so users dont have to do just that on most calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to implement it inside the Control to work for all calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like it's not needed anymore... just tested it without invoke (ThreadIDs are the same)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfkl : I think it might be interesting to avoid a lot of questions like this one : ZeBobo5/Vlc.DotNet#444
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's not needed : You are in a UI event handler, which runs on the dispatcher.
I guess that's it so far. Should be completly fixed and working |
Is it just me or did you forget to reference VideoLAN.LibVLC.Windows in the Sample project? The DLL is not found for me |
Thanks for your reactivity. For me, the WPF control is OK. However, the sample looks more like a test project. I think that we can choose only one of the two Examples and make it clean and commented for future users. We can keep the structure with a "launcher" window, or make a "Minimal" sample, as made in Vlc.DotNet. I just saw one bug : When the video is playing, closing the video window doesn't stop the player (audio is still playing). Please Dispose() properly the video control when the window is closing, so that users do the same. You might have to do that in another thread... |
I will consider that... EDIT: simple fix commited, player will stop now |
Fix issue of window closing and player keeps playing
Do you think |
I don't understand. What do you mean use an instance? |
I mean the something like
Same for |
No, if you're using the provided |
I call that a lazy initialization (as in the Lazy class). |
True, might be more often the case than NullException |
Can you tick that checkbox so I can push on that PR please? |
Made a PR on your fork. Please review the changes and next time use |
Fix renaming + cosmetics + rebase
Merged. |
https://twitter.com/martz2804/status/1019867718969782273 @Ch4rg3r thanks for your contribution, it's now live on nuget ;-) Feel free to keep those PRs coming! |
Thanks for merging and for your work. Great library 👍 |
This uses a WindowsFormsHost for better performance (HWND). Airspace issues have been worked around. Merge from GitHub PR #1, initiated by Ch4rg3r
This uses a WindowsFormsHost for better performance (HWND). Airspace issues have been worked around. Merge from GitHub PR #1, initiated by Ch4rg3r
Added Wpf UserControl with Autosizing using WindowsFormsHost