Page 1 of 1

VLC in WPF. Tutorial?

Posted: 26 Feb 2011 13:55
by EndLessMind
Hello everyone!

I'm currently using MediaElement in my WPF project, but even with DivX codec installed i can't get subtitles.
I've read that VLC got a WPF control. But i don't know how to find it and how to get it in to my project.

Is there anyone that know a tutorial on this or can help me with it.
I'm currently using VLC 1.1.5

If i can't get help with that, can anyone help me with the subtitles(.srt files)?
How to read them in the right way so i can use a textblock to display the subtitles.


Thanks in advance.

Re: VLC in WPF. Tutorial?

Posted: 27 Feb 2011 17:32
by Jean-Baptiste Kempf
ARe you using libvlc.net?

Re: VLC in WPF. Tutorial?

Posted: 28 Feb 2011 01:28
by EndLessMind
No, currently i'm not using any VLC components.
Because i don't know how to or that to use.

So i would be grateful if anyone could help me.
I've searched i found something in some old VLC forum, but that forum was back in the "Version 0.8"-days.
So i figured that it would not help me, and anyway, i didn't understand how to use that one either.

And the standard MediaElement is just not doing it for me, because if the lack of support for subtitles.
I've tried to install different subtitle-decoders and video-decoders but it didn't help.
That's why i want to use VLC. Because VLC is the BEST media-player out there.

Hope you can help me.

Thanks in advance!

Re: VLC in WPF. Tutorial?

Posted: 01 Mar 2011 09:36
by XilasZ
it's possible, yes.

To draw something, libvlc needs a handle, which doesn't exist in WPF.
A workaround is to use a WindowsFormsHost and put a winform panel inside it, and use the handle of this panel.

Note that in the same window, the WindowsFormsHost will always be drawn after all WPF components.

Another solution is to use vmem to get pixel data and display them yourself, but it's heavier to implement.

Re: VLC in WPF. Tutorial?

Posted: 01 Mar 2011 16:19
by EndLessMind
Okey, so i've added the WindowsFormsHost and a winform panel inside.
What should i do now?
Add the libVLC.dll in references?

Re: VLC in WPF. Tutorial?

Posted: 03 Mar 2011 20:46
by EndLessMind
You said the libvlc needs a handle.
How do i accomplish that?

Re: VLC in WPF. Tutorial?

Posted: 04 Mar 2011 15:04
by XilasZ
Host.Child.Handle will give you the handle, use that when calling libvlc_media_player_set_hwnd.

you should take a look at existing components such as libvlc.net. It's open source, so you can see how it works.

You can also take a look at my own source : http://fritivi.git.sourceforge.net/git/ ... ivi;a=tree

Re: VLC in WPF. Tutorial?

Posted: 04 Mar 2011 17:45
by EndLessMind
Thanks man :)

I've downloaded and built your project, so i could get the DLL.
But how do i add the VlcMediaPlayer to my panel in WindosFormsHost?
I tried:

Private Sub WindowsFormsHost1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles WindowsFormsHost1.Loaded
Dim pnl As New Windows.Forms.Panel
Dim VlcPlay As VlcMediaPlayer
pnl.Dock = Forms.DockStyle.Fill
pnl.Controls.Add(VlcPlay)
WindowsFormsHost1.Child = pnl
End Sub
But it gave me this error: " Value of type 'VideoLan.VlcMediaPlayer' cannot be converted to 'System.Windows.Forms.Control' "

I've tried to read your code to find out how you did, but can't seem to find it.

Re: VLC in WPF. Tutorial?

Posted: 08 Mar 2011 13:35
by XilasZ
VlcMediaPlayer is not meant to be used like that, there is not vlc user control.

see PlayUrl in FritiviPlayer to see how i use play something.