VideoLan.Interop a .Net libvlc 0.9.x wrapper

This forum is about all development around libVLC.
Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 29 Oct 2008 18:53

I've been using a wrapper I wrote for VLC 0.9.x. This wrapper is really just a small part of a larger project I work on. Although the source has always been available on sourceforge I never really made it public knowledge. Since it was brought up as an alternative in a different thread I thought I'd make my own support thread for anyone who wants to use it.

The source is available under LGPL at SourceForge;

http://meedios.svn.sourceforge.net/view ... /VideoLan/

This wrapper takes an object oriented approach to libvlc that eases the burden on developers. Sample code is also available at the svn repository above. I'm not posting any binaries. The library is not threadsafe. The following classes are also not implemented; list related classes (MediaList, Listplayer, ListView,...), VlcLog, and VLM classes.

If you have any questions or request then let me know.
Last edited by Kairos on 21 Jul 2009 06:01, edited 2 times in total.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net VLC 0.9.x wrapper

Postby Kairos » 29 Oct 2008 19:05

To answer some question from a previous thread
Kairos

Thank you for sharing your interop with us. Maybe you can start a new thread so that anyone can focus on developing or enhancing your interop. By the way, did you get to render vlc in wpf(i mean, full wpf features support)?

Thanks. Im gonna download it and test it.
Getting vlc to render in wpf is my primary goal. The project I work on, MeediOS, is 99% WPF. The 1% is a WinFormsHost with a panel that we use to render vlc on.
I tried VideoLanPlayer.UI. Is there any particular reason that you choose panel as the video container? just curious.
No reason.
Yes I have. Personally I'm not a big fan of just outputting the vlc pixelbuffer to the screen. The VLC Element (posted elsewhere on the forums) replaces the VLC vout module losing all the color space conversions and Direct3D goodies that make the picture look good.

I've been trying a different approach to get vlc in wpf. My goal is to modify the Direct3d vout module and libvlc. When the Direct3d module creates a new surface for rendering, it should send an event into vlc. libvlc should handle and expose that event as a surfacechanged event that my interop wrapper listens to. The event args should have a pointer to the new surface (or null if the surface was lost). Then in .net code you can use that surface pointer to hook up a D3DImage.

Unfortunately at this point I i've been unable to compile a vlc module from source, let alone all of vlc. I'm open to any way of getting vlc rendered in WPF, but ultimatly the solution must be as stable as rendering it to WindowsForms. The VLC Element I mentioned was never a stable for me.

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 30 Oct 2008 06:53

Kairos

i believe you are not the only one who have troubles compiling vlc for windows. i too have trouble compiling videolan for windows. and since, videolan team is short in windows developers, modifying direct3d vout module would be very hard. but the result if successful, is awesome. but maybe you can forward the idea to the windows developers of videolan hoping that they consider it future release.

what do you think j-b?

thanks.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 30 Oct 2008 09:02

i believe you are not the only one who have troubles compiling vlc for windows. i too have trouble compiling videolan for windows.
It seemed to be one problem after another trying to compile vlc on windows. I finally gave up and decided to cross compile from Ubuntu. Worked like a charm on the first try.
since, videolan team is short in windows developers, modifying direct3d vout module would be very hard.
short on windows devs! I can't imagine why. :D Anyway, I was planning on making the changes myself since I need wpf rendering ASAP. I've already been able to add my new module 'libd3dimage_plugin' to the tree and get it to compile. For the time being I'm just going to alter the new module and leave libvlc alone. I'll add hooks into the module that I can use to call into directly from the interop assembly. All in all, now that I can compile my module, its starting to look like wpf rendering may be possible.

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 30 Oct 2008 10:24

ive been trying to compile videolan like more than 10 times. only 1 succeeded. version 0.8.6i(by the time i got it, 0.9.2 got out. 0.9.2 packed with plethora of impressive features, so i decided to ditch 0.8.6i). tried in mingw32, cygwin, ubuntu, debian, mint. then i gave up.

but now you said you succesfully compiled it in ubuntu. i guess i have to try it one more times. thanks for the info :D.

by the way, its really a good news that you did not stuck in compiling (like i did) and figure out on what to do next.

thanks.

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:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Jean-Baptiste Kempf » 30 Oct 2008 12:17

Kairos

i believe you are not the only one who have troubles compiling vlc for windows. i too have trouble compiling videolan for windows. and since, videolan team is short in windows developers, modifying direct3d vout module would be very hard. but the result if successful, is awesome. but maybe you can forward the idea to the windows developers of videolan hoping that they consider it future release.

what do you think j-b?

thanks.
Compiling VLC is a pain, I know... My knowledge of Direct3D is near to 0, so well, I can't say.
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.

DennisL
New Cone
New Cone
Posts: 4
Joined: 30 Oct 2008 18:41

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby DennisL » 30 Oct 2008 20:19

First of all, thanks a lot for your VLC wrapper. But I have run into a problem. I used the wrapper pretty much the way like in your example. Whenever I start my playback app the first time, it play any movies I choose fine. But only until I end the app. On any subsequent start of my app it does not playback any files. The only way I found to correct this is to start VLC and start playback of a video. On the next start of my app it plays back any videos fine, but not on any subsequent starts. This behaviour is reproducable with your sample app as well (tested on two seperate machines).

Do you have any idea what the cause of this problem is?

Thanks.
Dennis

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 30 Oct 2008 20:52

Sounds like vlc may not be getting released properly when the application exits. When you close the program does it show the process as still running in the task manager? If that is the case you can try to manually call the Dispose() method on your VideoLanClient object when you close your application.

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 31 Oct 2008 07:19

Kairos

I was unable to use events provided by VlcEventArgs class. can u provide some example. actually, what im trying to do is to update the trackbar that shows current playing position. it works fine if i use Timer, but i want to use the events from VlcEventArgs.

thanks.

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 31 Oct 2008 09:01

Code: Select all

public Form1() { InitializeComponent(); videoLanClient = new VideoLanClient(); vlcMediaPlayer = videoLanClient.NewMediaPlayer(pnlVideo.Handle); vlcMediaPlayer.StateChanged += new EventHandler<StateChangedEventArgs>(vlcMediaPlayer_StateChanged); } void vlcMediaPlayer_StateChanged(object sender, StateChangedEventArgs e) { if (vlcMediaPlayer.State == VlcState.Playing) { trackBar.Maximum = (int)vlcMediaPlayer.Length; } }
this is the snippet of my code. im trying to set the trackbar to the length of the media. error that i get was "Cross-thread operation not valid: Control 'trackBar' accessed from a thread other than the thread it was created on." can someone shed a light on this.

by the way, where can i find example on how to use the events in videolan.interop.

thanks.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 31 Oct 2008 09:09

The events should be handled like any other .Net event. Right now VlcMediaPlayer is the only class I've added events to. The example code hooks into the timechanged event and the state changed event. I've noticed some problems with the events in libvlc.

A few caveats when using events;
1) Events are synchronous with vlc. You can block playback if you try to do too much in an event.
2) I deal with libvlc callback stuff internally and expose .net events to you. To avoid problems I suggest you always attach your events before you begin playing a file.

Code: Select all

_Vlc = new VideoLanClient(); _player = _Vlc.NewMediaPlayer(VideoPanel.Handle); _player.TimeChanged += new EventHandler<TimeChangedEventArgs>(_player_TimeChanged); _player.StateChanged += new EventHandler<StateChangedEventArgs>(_player_StateChanged); ... private void _player_TimeChanged(object sender, TimeChangedEventArgs e) { //tArg and tProp should be the same value but they are not. use tProp for now long tArg = e.Time; long tProp = _player.Time; } private void _player_StateChanged(object sender, StateChangedEventArgs e) { switch (e.NewState) { case VlcState.Ended: //The file ended play the next one break; case VlcState.Error: //Handle playing error break; case VlcState.Buffering: //Notify system is buffering break; } }
Personally I'd probably suggest you continue to use the timer. You can configure the increment of the timer, you don't block the vlc thread, and you can easily synchronize it (start/stop) using the StateChanged event on VlcMediaPlayer.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 31 Oct 2008 09:16

this is the snippet of my code. im trying to set the trackbar to the length of the media. error that i get was "Cross-thread operation not valid: Control 'trackBar' accessed from a thread other than the thread it was created on." can someone shed a light on this.

by the way, where can i find example on how to use the events in videolan.interop.

thanks.
Yes, the event is executing in the vlc thread, not your applications thread. WinForms UI elements cannot be directly accessed from another thread. You have to use Invoke or BeginInvoke in your code. Here is some background info for you on threading and winforms.

http://www.eggheadcafe.com/tutorials/as ... indow.aspx

mnn
New Cone
New Cone
Posts: 6
Joined: 12 Oct 2008 15:22

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby mnn » 31 Oct 2008 10:09

Code: Select all

void vlcMediaPlayer_StateChanged(object sender, StateChangedEventArgs e) { if (InvokeRequired == true) Invoke(new EventHandler<StateChangedEventArgs>(vlcMediaPlayer_StateChanged), sender, e); else { if (vlcMediaPlayer.State == VlcState.Playing) { trackBar.Maximum = (int)vlcMediaPlayer.Length; } } }

DennisL
New Cone
New Cone
Posts: 4
Joined: 30 Oct 2008 18:41

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby DennisL » 31 Oct 2008 10:18

Sounds like vlc may not be getting released properly when the application exits. When you close the program does it show the process as still running in the task manager? If that is the case you can try to manually call the Dispose() method on your VideoLanClient object when you close your application.
The process quits fine. I do not see anything left over. Dispose() gets called on the VideoLan-Object before the app quits. I am also able to reproduce the behaviour with the example app from the meedios repository. I am using the latest VLC 0.9.4, but 0.9.2 is giving the same results. The only way to do a "one time reset" is to run the main VLC application, start playback of any file and the use an app with your interop.

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 31 Oct 2008 22:00

Sounds like vlc may not be getting released properly when the application exits. When you close the program does it show the process as still running in the task manager? If that is the case you can try to manually call the Dispose() method on your VideoLanClient object when you close your application.
The process quits fine. I do not see anything left over. Dispose() gets called on the VideoLan-Object before the app quits. I am also able to reproduce the behaviour with the example app from the meedios repository. I am using the latest VLC 0.9.4, but 0.9.2 is giving the same results. The only way to do a "one time reset" is to run the main VLC application, start playback of any file and the use an app with your interop.
I'm really not sure what the problem is because I can't reproduce it at all. Do you have VLC installed or are you just using the zipped up binaries? Are you just pointing your app at the vlc install or are you copying all the vlc binaries over to your application?

DennisL
New Cone
New Cone
Posts: 4
Joined: 30 Oct 2008 18:41

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby DennisL » 01 Nov 2008 12:18

I'm really not sure what the problem is because I can't reproduce it at all. Do you have VLC installed or are you just using the zipped up binaries? Are you just pointing your app at the vlc install or are you copying all the vlc binaries over to your application?
I have the latest VLC release installed and read the installation dir from the registry. I then pass this path as argument to the constructor.

DennisL
New Cone
New Cone
Posts: 4
Joined: 30 Oct 2008 18:41

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby DennisL » 02 Nov 2008 18:08

I'm really not sure what the problem is because I can't reproduce it at all. Do you have VLC installed or are you just using the zipped up binaries? Are you just pointing your app at the vlc install or are you copying all the vlc binaries over to your application?
I did investigate on the issue a little further. When I copy the dlls over to my app, it works just fine. The issue does not come up and videos are played each and every time I start the app. On the other hand, when I point the app to a vlc install the error comes up. Maybe this might help you to track down the bug.

-Dennis

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 03 Nov 2008 11:00

Hi.

Ive created a simple player(and i mean really simple) to learn/test VideoLan.Interop from Kairos. Here are the source and executable.
http://www.syairin.com/SimplePlayer.7z

ImageImage

Steps
1. Extract to a folder
2. copy all dll from the main directory of latest videolan installation (tested with 0.9.4) to SimplePlayer\bin\Debug
3. copy plugins folder from the main directory of latest videolan installation (tested with 0.9.4) to SimplePlayer\bin\Debug
4. compile and run

Notes
1. the reason im using panel for video handle is because Kairos is using it for its video handle
2. the purpose of this is for learning. although i tried it to be as resource friendly as possible
3. if you have suggesion, feel free to comments
4. playlist is not implemented. maybe next time. maybe using videolan playlist, or .net playlist. i donno which one is better. although i believe, a .net playlist would be better
5. if you think i have bad naming habits, feel free to suggest

Features
1. Media position slider
2. Able to open media from files, streaming, etc. Can handle MRL options. see list of options here http://wiki.videolan.org/VLC_command-line_help
3. Volume slider
4. Play, Pause, Stop

Next
1. playlist
2. display metadata
3. (any suggestion)

Thanks.

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 04 Nov 2008 07:38

Line 136 in file Form1.cs

Code: Select all

if ( position < mediaTrackBar.Maximum || position > mediaTrackBar.Minimum)
should be

Code: Select all

if ( position < mediaTrackBar.Maximum && position > mediaTrackBar.Minimum)

publicENEMY
Cone that earned his stripes
Cone that earned his stripes
Posts: 104
Joined: 14 May 2007 05:04
Location: Malaysia

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby publicENEMY » 04 Nov 2008 10:58

Kairos.

How can i get media MRL, its options and media metadata during playback?

thanks.

m.e
Blank Cone
Blank Cone
Posts: 34
Joined: 27 Jan 2006 23:42

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby m.e » 04 Nov 2008 11:45

How can one get available subtitle tracks using this api?

SteveBickell
Blank Cone
Blank Cone
Posts: 13
Joined: 10 Sep 2008 01:18

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby SteveBickell » 10 Nov 2008 21:31

Hi Kairos,

Like you I have developed a .Net Libvlc wrapper for use in a larger project. It was originally inspired by the Marx wrapper but I ended up rewriting it and it now wraps almost all of the functions exported by Libvlc excluding VLM. Looking at your code they are remarkably similar (no handles visible, enumerable lists, simplified exception handling etc).One additional class I have developed deals with the myriad of options VLC has and tries to add proper validation and context checking but it's a long haul.

What your code enabled me to do was sort out events which I had never managed to get to work. The attribute declaration on the callback fixed my problem but that led on to another. Using your offsets in VlcCallbackArgs the callback data was always wrong apart from the first field (event type) until I changed offset 8 to offset 4 and offset 16 to offset 8 and then everyting was OK. Even the media handles passed in some callbacks pointed to media items I could access successfully.

Are you sure your offsets are correct?

Incidentally I agree with you that polling the status is (in most cases) a better option than using events.

If you manage to get a fully integrated WPF implementation to work you would be very popular in the WPF community. Apparently the MediaElement control is pretty limited (and unpopular).

Regards

Steve

Kairos
Blank Cone
Blank Cone
Posts: 45
Joined: 01 Mar 2008 01:49
Operating System: Windows
Location: Scottsdale, Az
Contact:

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby Kairos » 12 Nov 2008 08:17

On the contrary, I know my offsets are wrong. When I originally wrote it, I did the math and came out with the same offsets you stated. Problem was when I looked at the data it was all garbage. For some reason the computer I develop on stores each field as 8 bits :shock: . I have no idea why this happens, but in order to actually code and test the events I had to set the bit sizes to 8 bits. I usually switch them back when I compile for release mode. But thanks for pointing that out, I'll make that part of conditional compile code block.

Steve, your right. It is funny how similar they sound. I was planing on making a VlcConfiguration class to encapsulate the command line parameters. Ultimately I decided there was too much work for too little reward. Anyway, I'm glad my code was useful in getting your events working.

BexX
Blank Cone
Blank Cone
Posts: 18
Joined: 16 Jul 2008 00:26

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby BexX » 22 Nov 2008 13:47

this should be a sticky imho, because this wrapper is actually under development and more complete compared to marx wrapper.

BexX
Blank Cone
Blank Cone
Posts: 18
Joined: 16 Jul 2008 00:26

Re: VideoLan.Interop a .Net libvlc 0.9.x wrapper

Postby BexX » 22 Nov 2008 14:16

Hi Kairos,

i did some work on getting this wrapper to work on ubuntu/mono 1.91... and using this constructor it does work!

Code: Select all

// mono/linux Constuructor public VideoLanClient(string[] args) { //Initalize our exception pointer p_exception = new libvlc_exception_t(); p_exception.Initalize(); //create out vlc instance this.p_instance = InteropMethods.libvlc_new(args.Length, args, ref p_exception); p_exception.CheckException(); }
I am going to think about this whole constructor code in the VideoLanClient class and hopefully this thinking results in clean way working cross plattform! :)


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 18 guests