Hosting VLC Player in .NET Winforms – Part 3

Building A Player

Previously, in part 2, we covered the basic mechanics of accessing VLCs DLLs and creating the objects we need to make our own media player based on VLC.

If you’ve been reading thus far, you’ll have created three IntPtr handles :

  • A “session handle” to the DLL itself (hDllSession).
  • A media handle for the file we wish to play (lets call it hMedia)
  • A player handle in which to play the media (lets call it hPlayer)

I’m guessing you’ll want to play the media in its own window placed somewhere on a form. So add a panel to your winform – lets call the panel “panelVideo”. We tell VLC to paint on the panel by specifying the handle of the panelVideo (“panelVideo.Handle”).


Next, you need to tell the player what media source to use:-


Now you are ready to start playing your very first media file using the VLC DLLs:


Or, if you want to pause it:-


So, there you go. The very basics of a vlc-based player on your very own .NET form. But to make a usable player, you need take care of the incidental details. For example:-

  1. What happens if the media file is in a format that VLC doesn’t understand ? Well, this is a situation that can occur in many diverse situations where you say “cop this file matey” and whatever you are calling doesn’t understand the format and in almost every situation you either find the function you called returns a bool “false” or instead throws an exception. VLC gives you no hints whatever! We can infer it, but only by hooking up to events – which we shall cover next.
  2. If you’ve used DirectShow, you’ll probably be expecting that loading a file and calling “Pause” will push the first frame through thus initialising the video display. VLC doesn’t start displaying (or even recognising the media – the repercussions of which will be dealt with later) until you call start playing.

So, in the next part we’ll deal with events.

Leave a Reply