Page 1 of 4

More libvlc in C#

Posted: 16 Dec 2006 06:26
by Tappen
Updated Dec. 31 with cropping and configuration variable support. This is now in the Wiki at http://wiki.videolan.org/.Net_Interface_to_VLC so I am removing the old code from the forum.

Posted: 16 Dec 2006 06:29
by Tappen

Posted: 16 Dec 2006 10:46
by Jean-Baptiste Kempf
Thanks to both of you. I'll had those to the wiki when I have time.

Posted: 17 Dec 2006 23:00
by osmanosman
Firstly tahanks Tappen.
I'm beginner on C# and I can't build in Microsoft Visual C# 2005 Express Edition.
Can you sent project files to my email?
herneolursa@gmail.com

Posted: 18 Dec 2006 18:31
by osmanosman
I'm trying to buid exe.
I'm open a new project(Empty Project) in visual c#
and add these references
System
System.Dat
System.Deployment
....
and add
cs files
then
I'm geting this error when build.

Code: Select all

Error 1 Program 'C:\Documents and Settings\cagdas\Desktop\oooo\Project1\Project1\obj\Release\Project1.exe' does not contain a static 'Main' method suitable for an entry point Project1

Posted: 18 Dec 2006 19:28
by Tappen
osmanosman, your project needs to be a Windows Application, not an empty project. You need a host Form for this User Control to live on. The simplest arrangement is to open the main form in designer mode, use the Toolbox and drag a VlcUserControl onto the main form, then set its Dock property to Fill.

Posted: 18 Dec 2006 21:03
by osmanosman
Thank you very much..
It is ok.
We are waiting yours how to use wiki page..

Posted: 19 Dec 2006 23:58
by osmanosman
http://dhost.info/xaudio/vlcenc.html

Look here similar software.

Posted: 20 Dec 2006 10:59
by osmanosman
hi
I'm taking this error when using VLanControl.dll.
IntPtr vlc = vlc_current_object(vlcHandle);
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
what is my wrong

You are the man!

Posted: 20 Dec 2006 20:35
by sgross
This works great! I haven't had time to explore all the possiblities yet, but I can now show proof of concept on my projects! Let me know if I can help.

Posted: 21 Dec 2006 00:28
by Tappen
osmanosman be sure you call Initialize() on the NativeLibVlc object before making any other calls to it.

Also note I updated the post with newer code Dec. 18th. A couple bug fixes and added the DisplayMessage method.

Posted: 21 Dec 2006 10:49
by osmanosman
again Thank you Tappen!
this is better than activex :D

Posted: 21 Dec 2006 11:08
by Jean-Baptiste Kempf
Tappen, could you add all this stuff to the wiki ?

http://wiki.videolan.org/.Net_Interface_to_VLC

and the .Net/C# base page
http://wiki.videolan.org/C_Sharp

Thanks.

Posted: 21 Dec 2006 17:51
by osmanosman
I know I'm asking too much but I have a last question. :?
I have used this methot for activex.

Code: Select all

VLC.setVariable "conf::motiondetect-history", "5"
in vlccontrol I try this code:

Code: Select all

vlc1.SetVlcObjectString(ObjectType.VLC_OBJECT_VOUT, ":motiondetect-history", "5");
but it isn't working.

Posted: 21 Dec 2006 19:40
by Tappen
I don't have the code in front of me, but I think any setVariable in the activex control goes to VLC_OBJECT_INPUT. Also I think you want to call SetVlcObjectInt not SetVlcObjectString since the variable is an integer. Remember C# is type-safe unlike Javascript.

Trying to use this class in VB.net

Posted: 27 Dec 2006 02:25
by nkarnold
I've compiled your Class library in C# and created the VLanControl.DLL and then copied this into my VB.NET project as a reference

But I can't get the following to work

Dim VLC As New VLanControl.VlcUserControl

Dim options(0) As String

VLC.ClearPlayList()
VLC.AddToPlayList("dvd://d:@1", "", options)
VLC.Play()

Tracing through the class, in
public VlcError PlaylistClear()

it returns
return VlcError.NoObj;

Any ideas

Cheers

Native Video Size and Initialization Issue

Posted: 29 Dec 2006 00:47
by sgross
Is there a way to find out the native resolution of the video being displayed and then set the hosted form to that size, just like the native VLC player?

Also, I referenced the control by compiling your source and then importing the DLL into the ToolBox...
I have gotten a video to play to problem, but if I set the sound property at design time, it gives me the error osmanosman was having.

I call the Initialize() on the NativeLibVlc object, in the Control from your source in the OnLoad event. I tried moving it to the constructor with no luck.

Thanks for anyone who can help in advance.

Posted: 31 Dec 2006 04:03
by Tappen
nkarnold, I believe you need to set the parent of VLC to be your form and set its position and size to something reasonable, like ClientRectangle. Also, initialization of the native vlc only happens when the form the VlcUserControl is a child of is shown, so you can't do playlist calls immediately after you create it unless the form was already loaded and visible. I wait for the form_Load event in my own code before I start making calls.

sgross, I added a new video size property for my own use recently. I believe this is the size the video wants to play at, so it's the video width and height after being transformed by the aspect ratio. I'll post full new source when things are stable. There doesn't seem to be a way to get the internal rendering, input and output widths and heights without defining a lot of structs (whose members and sizes may change) in C#.

Full code is now in the Wiki at http://wiki.videolan.org/.Net_Interface_to_VLC

Code: Select all

[DllImport("libvlc")] static extern IntPtr libvlc_playlist_get_input(ref libvlc_instance_t libvlc, ref libvlc_exception_t p_exception); [DllImport("libvlc")] static extern void libvlc_input_free(IntPtr p_input); [DllImport("libvlc")] static extern int libvlc_video_get_width(IntPtr p_input, ref libvlc_exception_t p_exception); [DllImport("libvlc")] static extern int libvlc_video_get_height(IntPtr p_input, ref libvlc_exception_t p_exception); public Size VideoSize { get { try { using(VlcPlaylistObject vpobj = new VlcPlaylistObject(this.vlcHandle)) { if(vpobj.SubObject != IntPtr.Zero) { IntPtr p_input = libvlc_playlist_get_input(ref vpobj.libvlc, ref vpobj.exception); if(vpobj.exception.WasExceptionRaised()) { this.lastErrorMessage = Marshal.PtrToStringAnsi(vpobj.exception.psz_message); } else { try { int width = libvlc_video_get_width(p_input, ref vpobj.exception); if(!vpobj.exception.WasExceptionRaised()) { int height = libvlc_video_get_height(p_input, ref vpobj.exception); if(!vpobj.exception.WasExceptionRaised()) { return new Size(width, height); } } } finally { libvlc_input_free(p_input); } } } } } catch(Exception ex) { this.lastErrorMessage = ex.Message; } return new Size(); } }

Posted: 31 Dec 2006 04:50
by Tappen
sgross and osmanosman, I made a function that should work for setting config variables (see below). To do what osmanosman wanted, you'd call

SetConfigVariable("motiondetect-history", "5");

This will only work after Initialization like everything else, so put calls to this function in your form's load handler.

Full code is now in the Wiki at http://wiki.videolan.org/.Net_Interface_to_VLC

Code: Select all

enum CONFIG_ITEM : int { CONFIG_ITEM_STRING = 0x0010, CONFIG_ITEM_FILE = 0x0020, CONFIG_ITEM_MODULE = 0x0030, CONFIG_ITEM_INTEGER = 0x0040, CONFIG_ITEM_BOOL = 0x0050, CONFIG_ITEM_FLOAT = 0x0060, } [StructLayout(LayoutKind.Sequential)] struct module_config_t { public CONFIG_ITEM i_type; } [DllImport("libvlc")] static extern IntPtr config_FindConfig(IntPtr vlc, String name); [DllImport("libvlc")] static extern void __config_PutInt(IntPtr vlc, String name, int value); [DllImport("libvlc")] static extern void __config_PutFloat(IntPtr vlc, String name, float value); [DllImport("libvlc")] static extern void __config_PutPsz(IntPtr vlc, String name, String value); public VlcError SetConfigVariable(String name, String value) { using(VlcObject vlc = new VlcObject(this.vlcHandle, ObjectType.VLC_OBJECT_VLC)) { if(IntPtr.Zero == vlc.SubObject) { return VlcError.NoObj; } IntPtr p_item = config_FindConfig(vlc.SubObject, name); if(IntPtr.Zero == p_item) { return VlcError.NoVar; } else { try { module_config_t mod = (module_config_t)Marshal.PtrToStructure(p_item, typeof(module_config_t)); switch(mod.i_type) { case CONFIG_ITEM.CONFIG_ITEM_BOOL: { bool boolResult; if(Boolean.TryParse(value, out boolResult)) { __config_PutInt(vlc.SubObject, name, boolResult ? 1 : 0); } } break; case CONFIG_ITEM.CONFIG_ITEM_INTEGER: { int intResult; if(Int32.TryParse(value, out intResult)) { __config_PutInt(vlc.SubObject, name, intResult); } } break; case CONFIG_ITEM.CONFIG_ITEM_FLOAT: { float floatResult; if(Single.TryParse(value, out floatResult)) { __config_PutFloat(vlc.SubObject, name, floatResult); } } break; case CONFIG_ITEM.CONFIG_ITEM_STRING: __config_PutPsz(vlc.SubObject, name, value); break; default: return VlcError.NoVar; } } catch(Exception e) { this.lastErrorMessage = e.Message; return VlcError.Exception; } } } return VlcError.Success; }

Posted: 02 Jan 2007 00:10
by divx118
:) I want to use the dll as an activeX in hosted HTML. My knowledge of C# is very little at the moment (still learning).
What I did so far is compiled the project as stated in the Wiki. I checked the register as com in the building options.
Then I looked for the CLSID in the registry should be {7746CD88-5AF6-3FD9-ACD4-2E3D4239ED9E} and create an object with this in my HTML page.

Is it possible to do it this way or am I completely wrong?
I just wanted to use this control because the activeX 0.8.6 that is provided restricts me to much in the functions i can use in javascript.

Maurice

Posted: 02 Jan 2007 19:26
by Tappen
If you register the assembly by runnning:

regasm assemblyFile /codebase
(regasm.exe is in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727)

this should work. The object should be creatable in COM by GUID or full name. I haven't tested this, sorry, but it's worked in previous projects I've done.

Posted: 04 Jan 2007 18:50
by divx118
:) Thanks Tappen,

I tryed youre tip, but i don't get it to work it registers but i only get a white object and can't call any functions.
I have decided i will use the activeX 0.8.6 and use the options that you can add to the playlist items with vlc.playlist.add(mrl,name,options)
It gives me enough functionality. The only problem with this is that i have to do a lot of coding in javascript and you can't use the functions realtime when the video is playing.

Maurice

Posted: 04 Jan 2007 23:12
by rlomik
I use VLanControl.dll in Visual Studio 2005 C# project.
libvlc.dll and plugins folder (from vlc 0.8.6) are in the same directory with my player.

bug: If I setup VLC 0.8.5 or older in system then my VLanControl.dll-based player don't playing .
If no VLC or VLC 0.8.6 installed - player working excellently.

How fix this problem?

ps. sorry for my very bad english.

Posted: 05 Jan 2007 01:09
by Tappen
rlomik, have you tried setting the VlcInstallDir property of the NativeLibVlc object to the directory where the 0.8.6 libvlc.dll and plugins are before Initialize()?

This is the 1 small section of the code that I've left unchanged from osmanosman's original. I should probably just stop checking the registry for where VLC is installed, since the P/Invoke functions require libvlc.dll to be in the current directory or PATH anyway.

Posted: 12 Jan 2007 02:14
by Tappen
I updated the files and text in the Wiki. Notably the control can now be used as a replacement for the VLC ActiveX control. A sample html file is provided.