Page 1 of 3

Usage of libvlc.dll in C#

Posted: 15 Nov 2006 10:27
by boteasy
Hi,

I am developing an application for video conference and we are not prefer to use ActiveX as it needs admin right to register. Therefore, we want to use the libvlc.dll directly in C#. I am not experience in C#, does anyone have the sample?

Thanks.

Raymond.

Posted: 15 Nov 2006 19:53
by Odysee
Hi,
here is a sample for c#.

Code: Select all

/***************************************************************************** (C) Copyright by Odysee Module : LibVlc.cs SCCS : $Archive: $ $Revision: $ Author : Odysee Date : 10.11.2006 Last Change : $Date: $ $Author: $ Description : Known problems : Modification history : Date | Usr.| Comment ---------+-----+---------------------------------------------------------- | | ******************************************************************************/ using System; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; using Microsoft.Win32; namespace LibVlc { /**************************************************************************** Class name : LibVlc Author : Odysee Date : 22.12.2005 Description : Known problems : Modification history : Date | Usr.| Comment ---------+-----+---------------------------------------------------------- | | ****************************************************************************/ /// <summary> /// Class LibVlc /// </summary> public class LibVlc : IDisposable { //--------------------------------------------------------------------- // -- public enums #region public enums public enum Error { Success = -0, NoMem = -1, Thread = -2, Timeout = -3, NoMod = -10, NoObj = -20, BadObj = -21, NoVar = -30, BadVar = -31, Exit = -255, Generic = -666, Execption = -998, NoInit = -999 }; enum Mode { Insert = 0x01, Replace = 0x02, Append = 0x04, Go = 0x08, CheckInsert = 0x10 }; enum Pos { End = -666 }; #endregion //--------------------------------------------------------------------- //--------------------------------------------------------------------- // -- public structs #region public structs [StructLayout( LayoutKind.Explicit )] public struct vlc_value_t { [FieldOffset( 0 )] public Int32 i_int; [FieldOffset( 0 )] public Int32 b_bool; [FieldOffset( 0 )] public float f_float; [FieldOffset( 0 )] public IntPtr psz_string; [FieldOffset( 0 )] public IntPtr p_address; [FieldOffset( 0 )] public IntPtr p_object; [FieldOffset( 0 )] public IntPtr p_list; [FieldOffset( 0 )] public Int64 i_time; [FieldOffset( 0 )] public IntPtr psz_name; [FieldOffset( 4 )] public Int32 i_object_id; } #endregion //--------------------------------------------------------------------- //--------------------------------------------------------------------- // -- libvlc api #region libvlc api [DllImport("libvlc")] static extern int VLC_Create(); [DllImport("libvlc")] static extern Error VLC_Init(int iVLC, int Argc, string[] Argv); [DllImport("libvlc")] static extern Error VLC_AddIntf(int iVLC, string Name, bool Block, bool Play); [DllImport("libvlc")] static extern Error VLC_Die(int iVLC); [DllImport("libvlc")] static extern string VLC_Error(); [DllImport("libvlc")] static extern string VLC_Version(); [DllImport("libvlc")] static extern Error VLC_CleanUp(int iVLC); [DllImport("libvlc")] static extern Error VLC_Destroy(int iVLC); [DllImport("libvlc")] static extern Error VLC_AddTarget(int iVLC, string Target, string[] Options, int OptionsCount, int Mode, int Pos); [DllImport("libvlc")] static extern Error VLC_Play(int iVLC); [DllImport("libvlc")] static extern Error VLC_Pause(int iVLC); [DllImport("libvlc")] static extern Error VLC_Stop(int iVLC); [DllImport("libvlc")] static extern bool VLC_IsPlaying(int iVLC); [DllImport("libvlc")] static extern float VLC_PositionGet(int iVLC); [DllImport("libvlc")] static extern float VLC_PositionSet(int iVLC, float Pos); [DllImport("libvlc")] static extern int VLC_TimeGet(int iVLC); [DllImport("libvlc")] static extern Error VLC_TimeSet(int iVLC, int Seconds, bool Relative); [DllImport("libvlc")] static extern int VLC_LengthGet(int iVLC); [DllImport("libvlc")] static extern float VLC_SpeedFaster(int iVLC); [DllImport("libvlc")] static extern float VLC_SpeedSlower(int iVLC); [DllImport("libvlc")] static extern int VLC_PlaylistIndex(int iVLC); [DllImport("libvlc")] static extern int VLC_PlaylistNumberOfItems(int iVLC); [DllImport("libvlc")] static extern Error VLC_PlaylistNext(int iVLC); [DllImport("libvlc")] static extern Error VLC_PlaylistPrev(int iVLC); [DllImport("libvlc")] static extern Error VLC_PlaylistClear(int iVLC); [DllImport("libvlc")] static extern int VLC_VolumeSet(int iVLC, int Volume); [DllImport("libvlc")] static extern int VLC_VolumeGet(int iVLC); [DllImport("libvlc")] static extern Error VLC_VolumeMute(int iVLC); [DllImport("libvlc")] static extern Error VLC_FullScreen(int iVLC); [DllImport("libvlc")] static extern Error VLC_VariableType( int iVLC, string Name, ref int iType ); [DllImport("libvlc")] static extern Error VLC_VariableSet(int iVLC,string Name,vlc_value_t value ); [DllImport("libvlc")] static extern Error VLC_VariableGet(int iVLC,string Name,ref vlc_value_t value ); [DllImport("libvlc")] static extern string VLC_Error ( int i_err ); #endregion //--------------------------------------------------------------------- //--------------------------------------------------------------------- // -- local members #region local members private int m_iVlcHandle = -1; private Control m_wndOutput = null; private string m_strVlcInstallDir = ""; private string m_strLastError = ""; #endregion //--------------------------------------------------------------------- /// ------------------------------------------------------------------- /// <summary> /// Method name : LibVlc Constructor /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public LibVlc() { m_strVlcInstallDir = QueryVlcInstallPath(); } /*=======================================================================* *=======================================================================* *== IDisposable MEMBERS ==* *=======================================================================* *=======================================================================*/ #region IDisposable Members /// ------------------------------------------------------------------- /// <summary> /// Method name : Dispose /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public void Dispose() { if(m_iVlcHandle != -1) { try { VLC_CleanUp(m_iVlcHandle); VLC_Destroy(m_iVlcHandle); VideoOutput = null; } catch { } } m_iVlcHandle = -1; } #endregion /*=======================================================================* *=======================================================================* *== PUBLIC PROPERTIES ==* *=======================================================================* *=======================================================================*/ #region PUBLIC PROPERTIES /// ------------------------------------------------------------------- /// <summary> /// Method name : VlcInstallDir /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public string VlcInstallDir { get{return m_strVlcInstallDir;} set{m_strVlcInstallDir = value;} } /// ------------------------------------------------------------------- /// <summary> /// Method name : IsInitialized /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public bool IsInitialized { get{return (m_iVlcHandle != -1);} } /// ------------------------------------------------------------------- /// <summary> /// Method name : VideoOutput /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Control VideoOutput { get{return m_wndOutput;} set { // clear old window if(m_wndOutput != null) { m_wndOutput.Resize -= new EventHandler( wndOutput_Resize ); m_wndOutput = null; if(m_iVlcHandle != -1) SetVariable("drawable",0); } // set new m_wndOutput = value; if(m_wndOutput != null) { if(m_iVlcHandle != -1) SetVariable("drawable",m_wndOutput.Handle.ToInt32()); m_wndOutput.Resize += new EventHandler( wndOutput_Resize ); wndOutput_Resize(null,null); } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : LastError /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public string LastError { get{return m_strLastError;} } /// ------------------------------------------------------------------- /// <summary> /// Method name : IsPlaying /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public bool IsPlaying { get { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return false; } try { return VLC_IsPlaying(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return false; } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : LengthGet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public int LengthGet { get { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } try { return VLC_LengthGet(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : TimeGet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public int TimeGet { get { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } try { return VLC_TimeGet(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : PositionGet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public float PositionGet { get { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } try { return VLC_PositionGet(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : VolumeGet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public int VolumeGet { get { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } try { return VLC_VolumeGet(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } } /// ------------------------------------------------------------------- /// <summary> /// Method name : Fullscreen /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public bool Fullscreen { get { int iIsFullScreen = 0; if(GetVariable("fullscreen",ref iIsFullScreen) == Error.Success) if(iIsFullScreen != 0) return true; return false; } set { int iFullScreen = value ? 1 : 0;; SetVariable("fullscreen",iFullScreen); } } #endregion /*=======================================================================* *=======================================================================* *== PUBLIC METHODS ==* *=======================================================================* *=======================================================================*/ #region PUBLIC METHODS /// ------------------------------------------------------------------- /// <summary> /// Method name : Initialize /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public bool Initialize() { // check if already initializes if(m_iVlcHandle != -1) return true; // try init try { // create instance m_iVlcHandle = VLC_Create(); if (m_iVlcHandle < 0) { m_strLastError = "Failed to create VLC instance"; return false; } // make init optinons string[] strInitOptions = { "vlc", "--no-one-instance", "--no-loop", "--no-drop-late-frames", "--disable-screensaver"}; if(m_strVlcInstallDir.Length > 0) strInitOptions[0] = m_strVlcInstallDir + @"\vlc"; // init libvlc Error errVlcLib = VLC_Init(m_iVlcHandle, strInitOptions.Length, strInitOptions); if (errVlcLib != Error.Success) { VLC_Destroy(m_iVlcHandle); m_strLastError = "Failed to initialise VLC"; m_iVlcHandle = -1; return false; } } catch { m_strLastError = "Could not find libvlc"; return false; } // check output window if(m_wndOutput != null) { SetVariable("drawable",m_wndOutput.Handle.ToInt32()); wndOutput_Resize(null,null); } // OK return true; } /// ------------------------------------------------------------------- /// <summary> /// Method name : AddTarget /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error AddTarget(string Target) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_AddTarget(m_iVlcHandle, Target, null, 0, (int)Mode.Append, (int)Pos.End); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : AddTarget /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error AddTarget(string Target, string[] Options) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } // check options int iOptionsCount = 0; if(Options != null) iOptionsCount = Options.Length; // add Error enmErr = Error.Success; try { enmErr = VLC_AddTarget(m_iVlcHandle, Target, Options, iOptionsCount, (int)Mode.Append, (int)Pos.End); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : Play /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error Play() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_Play(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : Pause /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error Pause() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_Pause(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : Stop /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error Stop() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_Stop(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : SpeedFaster /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public float SpeedFaster() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } Error enmErr = Error.Success; try { return VLC_SpeedFaster(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } /// ------------------------------------------------------------------- /// <summary> /// Method name : SpeedSlower /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public float SpeedSlower() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } Error enmErr = Error.Success; try { return VLC_SpeedSlower(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } /// ------------------------------------------------------------------- /// <summary> /// Method name : PlaylistNext /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error PlaylistNext() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_PlaylistNext(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : PlaylistPrevious /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error PlaylistPrevious() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_PlaylistPrev(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : PlaylistClear /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error PlaylistClear() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_PlaylistClear(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : TimeSet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error TimeSet(int newPosition, bool bRelative) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_TimeSet(m_iVlcHandle, newPosition, bRelative); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : PositionSet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public float PositionSet(float newPosition) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } try { return VLC_PositionSet(m_iVlcHandle, newPosition); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } /// ------------------------------------------------------------------- /// <summary> /// Method name : VolumeSet /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public int VolumeSet(int newVolume) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return -1; } Error enmErr = Error.Success; try { return VLC_VolumeSet(m_iVlcHandle, newVolume); } catch(Exception ex) { m_strLastError = ex.Message; return -1; } } /// ------------------------------------------------------------------- /// <summary> /// Method name : VolumeMute /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error VolumeMute() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_VolumeMute(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : SetVariable /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error SetVariable(string strName, Int32 Value) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { // create vlc value vlc_value_t val = new vlc_value_t(); val.i_int = Value; // set variable enmErr = VLC_VariableSet(m_iVlcHandle,strName,val); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : SetVariable /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error GetVariable(string strName, ref int Value) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { // create vlc value vlc_value_t val = new vlc_value_t(); // set variable enmErr = VLC_VariableGet(m_iVlcHandle,strName,ref val); Value = val.i_int; } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : ToggleFullscreen /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error ToggleFullscreen() { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { enmErr = VLC_FullScreen(m_iVlcHandle); } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } /// ------------------------------------------------------------------- /// <summary> /// Method name : ToggleFullscreen /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- public Error PressKey(string strKey) { if(m_iVlcHandle == -1) { m_strLastError = "LibVlc is not initialzed"; return Error.NoInit; } Error enmErr = Error.Success; try { // create vlc value vlc_value_t valKey = new vlc_value_t(); // get variable enmErr = VLC_VariableGet(m_iVlcHandle,strKey,ref valKey); if(enmErr == Error.Success) {// set pressed enmErr = VLC_VariableSet(m_iVlcHandle,"key-pressed",valKey); } } catch(Exception ex) { m_strLastError = ex.Message; return Error.Execption; } if((int)enmErr < 0) { m_strLastError = VLC_Error((int)enmErr); return enmErr; } // OK return Error.Success; } #endregion /*=======================================================================* *=======================================================================* *== PRIVATE METHODS ==* *=======================================================================* *=======================================================================*/ #region PRIVATE METHODS /// ------------------------------------------------------------------- /// <summary> /// Method name : QueryVlcInstallPath /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- private string QueryVlcInstallPath() { // open registry RegistryKey regkeyVlcInstallPathKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\VideoLAN\VLC"); if(regkeyVlcInstallPathKey == null) return ""; return (string)regkeyVlcInstallPathKey.GetValue("InstallDir",""); } #endregion /*=======================================================================* *=======================================================================* *== EVENT METHODS ==* *=======================================================================* *=======================================================================*/ #region EVENT METHODS /// ------------------------------------------------------------------- /// <summary> /// Method name : wndOutput_Resize /// Author : Odysee /// Date : 10.11.2006 /// </summary> /// ------------------------------------------------------------------- void wndOutput_Resize( object sender, EventArgs e ) { if(m_iVlcHandle != -1) { SetVariable("conf::width", m_wndOutput.ClientRectangle.Width); SetVariable("conf::height",m_wndOutput.ClientRectangle.Height); } } #endregion } }
I have also written a wrapper in managed c++ (assembly)! If you want, i can mail you the project!

ciao Odysee

Posted: 16 Nov 2006 03:40
by boteasy
Hello Odysee,

Thank for your sample and I'll try it today.

It's great if you can email the wrapper project to me. My email is boteasy@yahoo.com

Thanks.

Raymond.

Posted: 16 Nov 2006 09:49
by Odysee
Mail is on the way...

Posted: 16 Nov 2006 21:05
by sgross
Odysee:

I just tried your C# Wrapper and I was getting an exception when initialing it. It was saying that the DLL was not registered?

VLC is obviously installed in my machine and I am able to use the ActiveX control, but would rather use LibVlc.

Could you provide a little more to that sample?

Thank you

Posted: 17 Nov 2006 00:37
by Tappen
sgross

Make sure your current working directory is the directory containing libvlc.dll when you launch your executable.

Posted: 17 Nov 2006 07:48
by Odysee
Yes, the Path variable must contain the path to the libvlc.dll ;)
Or you can tempoarly set the path with System.Enviroment in you app.

How to add VLC Windows in a Windows Form?

Posted: 17 Nov 2006 11:57
by ZeBobo5
Thanks for the sample code.
How to add the VLC Windows in a Windows Form?

Tx

Posted: 17 Nov 2006 13:10
by Odysee
1. Add a PictureBox or something with a Handle into the form (with dockstyle=fill)

2. Set the PicturBox as Control to the Wrapper with MyLibDll.VideoOutput = MyPictureBox

That's all...

Posted: 20 Nov 2006 21:24
by sgross
Got it. Thank you for your help.

Generally speaking, is it a better idea to use LibVlc then the ActiveX control, aside from it having more functionality?

Posted: 21 Nov 2006 00:53
by cioris
It seems you have a lot of experience in using libvlc.dll.
I have a quick question about VLC_Init. The first parameter should point to the VLC install directory, right?

What about the case we have a machine without VLC? In fact, I would like to develop a program based on libvlc, but I don't want to install VLC package on every single machine. Any thoughts?

Thanks...

Posted: 21 Nov 2006 08:50
by Odysee
Use a Network Drive and install (copy only) the vlc package on it!
I haven't tried it so far, but it must work!

Posted: 21 Nov 2006 19:29
by cioris
This is a nice trick.. :D , but I was wondering why do we need the .exe file. Looking into the code, it seems we need to point to the library not to the executable, right?

I suppose the libvlc.dll file should be more than enough. The code is in the dll, not in the .exe file.

So, did somebody try to use .dll w/o installing the VLC package?

Thanks...

Posted: 22 Nov 2006 07:46
by Odysee
Hi,

yes, you really need only the libvlc.dll and some plugins! You don't must install, the package!

Posted: 22 Nov 2006 18:03
by cioris
Got it!
The plugins directory should be included in the new project.

Thanks...

Posted: 05 Dec 2006 16:20
by MKay
Hi,

thx for sharing the code. ;)
But i have a question on using this source. :)

I created an instance of the class and called the initialize-function:

Code: Select all

LibVlc.LibVlc Test = new LibVlc.LibVlc(); Test.Initialize();
After that Test.LastError contains the value "variable not found" and i can not use the functions.
Can somebody help me?

best regards,
MKay

Posted: 14 Dec 2006 18:14
by stacy3477
Odysee,

Looks like great work! You mentioned that you also have a managed C++ version. IYO, would it be difficult to port it to straight VC++? Could I (stacy3477@hotmail.com) get a copy of it to look at?

TIA,
Stacy

Posted: 14 Dec 2006 19:12
by Jean-Baptiste Kempf
Odysse, do you authorize your work to be put on VideoLAN's wiki ?
Copyright ? Licence ?

Posted: 14 Dec 2006 20:35
by Odysee
Odysse, do you authorize your work to be put on VideoLAN's wiki ?
Copyright ? Licence ?
Yes, of course ;)

Posted: 14 Dec 2006 21:25
by stacy3477
Great! Will you post the link to the wiki on this forum once you're done?

Posted: 28 Dec 2006 12:52
by zbe
Hello

how can I tell libvlc to stream over udp (--sout-standard-access=udp --sout-standard-mux=ts --sout-standard-url=<IP address>:<port>) ?

Posted: 29 Dec 2006 15:14
by MAK
Can any one help me: what plugins i must include from plugins to my solution to play most videos without installed codecs?

Posted: 31 Dec 2006 06:01
by Tappen
MAK if you're using this interface you can probably drop wxwidgets, skins2, x264 (no h.264 for you), freetype(if you don't care about sub-titles). Anything that has dvd in the name if you don't care about them.

Posted: 19 Jan 2007 16:23
by ParKiN
Hi everybody, I made a project in VS 2005 to use LibVlc.cs.

I first created a Windows Application (containing Form1.cs and Program.cs), then I made a class called LibVlc.cs.

In Form1.cs, I only have:

Code: Select all

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace CustomVlcPlayer { public partial class Form1 : Form { public Form1() { InitializeComponent(); LibVlc.LibVlc vlc = new LibVlc.LibVlc(); vlc.Initialize(); MessageBox.Show(vlc.LastError); vlc.VideoOutput = pictureBox1; vlc.PlaylistClear(); vlc.AddTarget("F:\\....\\matrix.mpg"); vlc.Play(); } } }
I cannot import the libvlc.dll file, when i did right click on the project then "add reference...", search the libvlc.dll file and "ok" i have the error message :

Une reference a "D:\....\libvlc.dll" n'a pas pu etre ajoutee. Assurez vous que le fichier est accessible et qu'il s'agit d'un assembly valide ou d'un composant COM

If I run the project without libvlc.dll in my project, I have this error :
could not find libvlc
This is normal !

Am I doing something wrong ? if yes, can someone help me with that and give me the correct solution to succeed?

thank you very much.

ParKiN

Posted: 19 Jan 2007 18:03
by Tappen
I've put a sample C# project which uses libvlc.dll in the wiki http://wiki.videolan.org/.Net_Interface_to_VLC. It's quite a bit of work to call libvlc from .Net.