Introduction
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:
[DllImport("libvlc")]
static extern int VLC_Create();
[DllImport("libvlc")]
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;
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:
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();
break;
}
}
}
if (!bFound) {
Point pie = new Point(350, 350);
IntPtr hIE = Win32.WindowFromPoint(pie);
vHandle = hIE.ToInt32();
}
Summary
If you have any questions about LiquidVideo™, please feel free to contact me at:
Bill SerGio
tvmogul1@yahoo.com