More libvlc in C#

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

More libvlc in C#

Postby Tappen » 16 Dec 2006 06:26

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.
Last edited by Tappen on 01 Jan 2007 02:50, edited 2 times in total.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 16 Dec 2006 06:29

Last edited by Tappen on 01 Jan 2007 02:52, edited 2 times in total.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Postby Jean-Baptiste Kempf » 16 Dec 2006 10:46

Thanks to both of you. I'll had those to the wiki when I have time.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 17 Dec 2006 23:00

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

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 18 Dec 2006 18:31

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

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 18 Dec 2006 19:28

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.

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 18 Dec 2006 21:03

Thank you very much..
It is ok.
We are waiting yours how to use wiki page..

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 19 Dec 2006 23:58

http://dhost.info/xaudio/vlcenc.html

Look here similar software.

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 20 Dec 2006 10:59

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

sgross
Blank Cone
Blank Cone
Posts: 14
Joined: 16 Nov 2006 20:57

You are the man!

Postby sgross » 20 Dec 2006 20:35

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.
Last edited by sgross on 21 Dec 2006 03:52, edited 1 time in total.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 21 Dec 2006 00:28

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.

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 21 Dec 2006 10:49

again Thank you Tappen!
this is better than activex :D

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Postby Jean-Baptiste Kempf » 21 Dec 2006 11:08

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.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

osmanosman
Blank Cone
Blank Cone
Posts: 32
Joined: 25 Oct 2006 12:47

Postby osmanosman » 21 Dec 2006 17:51

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.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 21 Dec 2006 19:40

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.

nkarnold
Blank Cone
Blank Cone
Posts: 12
Joined: 20 Sep 2006 13:47

Trying to use this class in VB.net

Postby nkarnold » 27 Dec 2006 02:25

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

sgross
Blank Cone
Blank Cone
Posts: 14
Joined: 16 Nov 2006 20:57

Native Video Size and Initialization Issue

Postby sgross » 29 Dec 2006 00:47

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.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 31 Dec 2006 04:03

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(); } }
Last edited by Tappen on 01 Jan 2007 18:47, edited 2 times in total.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 31 Dec 2006 04:50

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; }

divx118
Blank Cone
Blank Cone
Posts: 95
Joined: 22 Jun 2006 18:19

Postby divx118 » 02 Jan 2007 00:10

:) 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

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 02 Jan 2007 19:26

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.

divx118
Blank Cone
Blank Cone
Posts: 95
Joined: 22 Jun 2006 18:19

Postby divx118 » 04 Jan 2007 18:50

:) 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

rlomik
New Cone
New Cone
Posts: 1
Joined: 04 Jan 2007 22:46

Postby rlomik » 04 Jan 2007 23:12

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.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 05 Jan 2007 01:09

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.

Tappen
Cone that earned his stripes
Cone that earned his stripes
Posts: 150
Joined: 30 Oct 2006 07:55

Postby Tappen » 12 Jan 2007 02:14

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.


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 11 guests