Click here to Skip to main content
Click here to Skip to main content
Go to top

LiquidVideo, Play Video Anywhere with VLC C# .NET VideoLan

, 23 Aug 2011
Rate this:
Please Sign up or sign in to vote.
Play Video anywhere with VideoLan VLC C# .NET Interface
Screenshot - liquidvideo1.gif


This is a C# VS2005 version of my LiquidVideo that was originally written in C++ that uses a C# .NET Interface to the vlc library, libvlc.dll, that requires just a few lines of code to play video. VLC (i.e., VideoLan) is considered by many to be the best media player in the world. There is no question that it is vastly superior to the Windows Media Player.
For a more complete, FREE, C# .NET Interface to the VideoLAN (VLC) media player, see:

With just the few lines of C# code in this sample, you have a media player in this demo that has far more features and effects than the Window Media Player.

This is a fun program for playing video anywhere, in any window, or HTML element, in any shape, using the window or object's handle, even objects like an Applet Tag in a web page.

This article and demo illustrates the following:

  • C# .NET Interface to the vlc library (NOT the activex control)
  • Finding the handle to any window under the mouse
  • How to load a region (.rgn) file in C#

How to Use the Video Dropper

Simply right-mouse down on the Video Dropper in the screen and drag it over the window or web page element like an applet that you want to play video in, release, and then press the Play button. For example, open your browser and play video in any web page.

VLC Plugins and Pathway Settings

This program does NOT require you to install the vlc media player or any other media players. It does NOT use the vlc activex control. It uses a very simple .NET Interface to the vlc library, VLC.cs, to play video and access all of the vlc plugins.

I posted 3 zipped files of all of the most important vlc plugins including all of the DirectX effects that you can apply to any video. You can play almost anything from DVDs to streaming television and transcode and save videos in any video file formats.

You must download and install the plugins in the plugins directory inside of the bin directory. I only included the very minimum plugins needed to play video and you really should download all the vlc plugins from the vlc website and install them in this plugins directory.

The executable, liquidvideo.exe, and the vlc library DLL, libvlc.dll, must be in the same directory that the plugins directory is located inside of in order to work.

The interface is created by simply declaring the functions found in vlc's source code. You can easily add any additional functions from vlc you might want to add like these were added:

static extern int VLC_Create(); 
static extern Error VLC_Init(int iVLC, int Argc, [MarshalAs(UnmanagedType.LPArray,
     ArraySubType = UnmanagedType.LPStr)]string[] Argv);

To create a handle to the library, i.e., iVLC, you just call:

this.iVLC = VLC_Create();

To play video in any window, control, region, or object, you just pass the handle to VLC_VariableSet as an integer as follows:

public void SetOutputWindow(int outputWindow)
     if (outputWindow > 0)
          VLC_VariableSet(iVLC, "drawable", outputWindow);

How to Set Video Options like "Snapshot"

You can set video options to do things like take a "Snapshot" of the playing video. Notice the button with the picture of a camera on the screen? Well, this button takes a snapshot by simply setting an option. To take a snapshot, you would just call "setVariable" to set a snapshot key and then again to press that key you set. In this example, I set the letter "S" as a snapshot key below:

if (vlc.playing)
   ushort skey = 0x53; /* S key */
   vlc.setVariable("key-snapshot", (int)skey);
   vlc.setVariable("key-pressed", (int)skey);

Why Did I Bother with A Non-Rectangular Skin?

Why did I include a non-rectangular skin? It wasn't just to create a cool looking GUI, it was to allow you to try playing video in non-rectangular shapes. The best way to illustrate this is to create a .html file with a <applet></applet> tag and specify some size to give it the standard rectangle shape. Applet tags create areas that have handles so you can use the eye dropper to play video in a reactangular applet. Take and add a few lines of code to apply the back.rgn region to applet and you will see video playing in a web page in a non-rectangular shape. To create the skin for the main window I created a region file, back.rgn, from the bitmap, back.bmp, and load the region as follows:

/* read region data from disk into a byte array */
   byte[] regionData = null;
   using (FileStream fs = new FileStream(vlcInstallDirectory + 
	@"\back.rgn", FileMode.Open, FileAccess.Read, FileShare.Read))
      BinaryReader reader = new BinaryReader(fs);
      regionData = reader.ReadBytes((int)fs.Length);
   this.Region = Region.FromHrgn(ExtCreateRegion(0, regionData.Length, regionData));

Play Video Inside Internet Explorer

You can play video inside Internet Explorer by getting a handle to the current tab as follows:

bool bFound = false;
IntPtr hwnd = System.IntPtr.Zero;
if (!bIELauncheded) {
   bIELauncheded = true;
   SHDocVw.ShellWindows SWs = new ShellWindows();
   IE = new InternetExplorer();
   IE.Visible = true;
   object o = new object();
   IE.Navigate("about:blank", ref o, ref o, ref o, ref o);
IEnumerator windows = new SHDocVw.ShellWindowsClass().GetEnumerator();
while (!bFound && windows.MoveNext()) {
   if ((windows.Current is SHDocVw.IWebBrowser2) 
      && ((windows.Current as SHDocVw.IWebBrowser2).HWND == IE.HWND)) {
      ((windows.Current as SHDocVw.IWebBrowser2).Document 
		as IOleWindow).GetWindow(out hwnd);
      if (IsWindowVisible(hwnd)) {
         bFound = true;
         vHandle = hwnd.ToInt32();
if (!bFound) {
   Point pie = new Point(350, 350);
   IntPtr hIE = Win32.WindowFromPoint(pie);
   vHandle = hIE.ToInt32();


If you have any questions about LiquidVideo, please feel free to contact me at:

Bill SerGio


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

William SerGio
Software Developer (Senior)
United States United States
I love coding and develop desktop apps (C++, C#, Java), websites, and mobile apps (iPhone, Android, Blackberry, iPad, PhoneGap/Cordova).
I am launching a new national TV series that features the best mobile apps. Show me your apps!
I have written software for Microsoft,, Quicken (Intuit), Mellon Bank, U.S. Army, U.S. Navy, Franklin Templeton, Pepsi, Universal Studios, Ryder Systems, AVID, Media 100, etc.
Bill SerGio

You may also be interested in...

Comments and Discussions

QuestionGreat work!!! Thanks PinmemberMember 106678156-Jun-14 20:06 
QuestionOther video formats PinmemberBronek4-Jun-12 21:47 
GeneralMy vote of 5 PinmemberBill SerGio, The Infomercial King24-Oct-11 3:47 
QuestionCould not see movie Pinmemberdpan8811-Sep-11 6:19 
AnswerRe: Could not see movie PinmemberBill SerGio, The Infomercial King11-Sep-11 9:13 
GeneralRe: Could not see movie PinmemberMehran Aghemiri7-Mar-13 7:01 
QuestionCould not find libvlc Pinmembertahri jouti30-Aug-11 22:25 
AnswerRe: Could not find libvlc PinmemberBill SerGio, The Infomercial King30-Aug-11 23:04 
AnswerRe: Could not find libvlc Pinmemberalainmazy12-Sep-11 22:40 
GeneralRe: Could not find libvlc Pinmembertahri jouti12-Sep-11 22:42 
GeneralRe: Could not find libvlc PinmemberBill SerGio, The Infomercial King7-Mar-13 10:00 
Questionnew wrappers? Pinmemberzomorrod.company1-Nov-13 6:27 
Question403.html Pinmemberagorby24-Aug-11 1:33 
AnswerRe: 403.html PinmemberBill SerGio, The Infomercial King24-Aug-11 5:10 
GeneralVery strange... Pinmemberagorby24-Aug-11 23:35 
GeneralRe: Very strange... Pinmemberandywebsdale11-Sep-11 4:23 
GeneralRe: Very strange... PinmemberBill SerGio, The Infomercial King11-Sep-11 9:14 
GeneralThis is unlove IE 8 by's wiki :) Pinmemberagorby12-Sep-11 23:08 
GeneralRe: This is unlove IE 8 by's wiki :) Pinmemberandywebsdale12-Sep-11 23:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 23 Aug 2011
Article Copyright 2011 by William SerGio
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid