Difference between revisions of ".Net Interface to VLC"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 8: Line 8:
 
  - added ActiveX functionality
 
  - added ActiveX functionality
 
  - added redundant interfaces to support Javascript programming because Javascript doesn't support ActiveX arrays or Out parameters
 
  - added redundant interfaces to support Javascript programming because Javascript doesn't support ActiveX arrays or Out parameters
 +
- fixed install directory dependence.  Now the directory the assembly exists in is always used as the install directory.
 
  - fixed PlaylistIndex and PlaylistCount properties
 
  - fixed PlaylistIndex and PlaylistCount properties
 
  - fixed Cropping
 
  - fixed Cropping

Revision as of 01:01, 12 January 2007

I started with Odysee's work [1] and wrote a .Net user control that uses libvlc interfaces to do what the ActiveX control does and more, like getting info about and getting/setting audio and subtitle tracks, aspect ratios, deinterlacing filters and more. This compiles in Visual C#.Net Express, free from Microsoft [2].

I should say this works with VLC 0.8.6 and 0.8.6a, no guarantees for other versions. Any dll or exe you create with this code needs to be in the same directory as libvlc.dll and have the plugins sub-directory below it. One common error is to forget to call Initialize() on the VlcUserControl instance, which must be done after the control has been parented to a form and the form is visible (the form_OnLoad event is best).

Tappen

Update Jan. 11, 2007:

- added ActiveX functionality
- added redundant interfaces to support Javascript programming because Javascript doesn't support ActiveX arrays or Out parameters
- fixed install directory dependence.  Now the directory the assembly exists in is always used as the install directory.
- fixed PlaylistIndex and PlaylistCount properties
- fixed Cropping
- added NowPlaying event, and ProducingEvents property which controls it
- added Contrast, Brightness, Hue, Saturation, Gamma properties and AllowVideoAdjustments property which controls them
- added GetConfigVariable method
- added VLanControl.snk file to allow the control to be signed, required by ActiveX 
- added Test.html file to demonstrate ActiveX usage

Register the dll for use as an ActiveX component by running:

   %WINDIR%\Microsoft.net\Framework\v2.0.50727\regasm VLanControl.dll /codebase

IPlayer.cs is the main Interface supported by VlcUserControl, since something like this deserves the Bridge pattern treatment. IPlayer.cs should really be in a different assembly from the control to allow other controls to support it and be used interchange-ably with VlcUserControl but that's up to you developers.

NativeLibVlc.cs contains the .Net Interop versions of the native VLC C++ structures and functions, and a class which wraps these calls in C#.

VlcUserControl.cs contains the non-designer part of the VlcUserControl class, derived from System.Windows.Forms.UserControl, which can be used either directly on C# forms, or as an ActiveX control if wrapped and registered in a dll. VlcUserControl acts mostly as a wrapper for the NativeLibVlc.cs functions, but also has a few complications such as allowing multiple playback position moves in quick succession or when paused, since VLC, as an asynchronous player, will not return the correct position for a significant part of a second after a move. VlcUserControl also handles (optionally, default is on, variable bool useVlcCrop) cropping instead of using the VLC cropping feature, (see InnerVlcWindow.cs comment below for explanation). Thirdly, VlcUserControl attempts to minimize the inaccuracy of moving by timestamp in Mpeg-2 files since VLC doesn't do this well (optional, default is off, variable bool useMpegVbrOffset).

VlcUserControl.Designer.cs contains the designer part of the VlcUserControl class.

VlcUserControl.resx contains the layout and resource definition of the VlcUserControl class.

InnerVlcWindow.cs is an essentially empty class. One instance is created as a child window by each VlcUserControl class instance where VLC will actually draw the video. This allows VlcUserControl to act as a "viewport" and crop the VLC output since the cropping filter of VLC leaves something to be desired when used in a player application (it can't co-exist with DeInterlace filters most importantly).

InnerVlcWindow.Designer.cs contains the designer part of the InnerVlcWindow class.

AssemblyInfo.cs is an optional file containing sample assembly information if the above classes are placed in a separate dll module in your code hierarchy. As usual in .Net 2.0 projects, it should be placed in a sub-directory named "Properties".

VLanControl.csproj is an optional project file for all the above files.

VLanControl.snk is an optional key file for use in signing the dll.

Test.html is an optional ActiveX demonstration file.