libvlcnet - .NET library based on libvlc

This forum is about all development around libVLC.
elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

libvlcnet - .NET library based on libvlc

Postby elwood » 21 Apr 2009 17:57

Today the first public version of library has been released. Library provides basic functionality to play a movies and music files. If you looking for a simple solution to implement features like playing mediafiles, transcoding into another formats or network streaming, it may be useful for you. Library includes .NET interop code, abstract classes, Windows Forms user controls and sample player written using Windows Forms.

Project homepage at SourceForge : https://sourceforge.net/projects/libvlcnet/

Works on Microsoft .NET 2.0, 3.5, releases for Linux planned in the future.

The sources and binaries is available under GPL at SourceForge:
https://sourceforge.net/project/showfil ... _id=242685

To build library using NAnt, execute command like this:
nant /t:net-2.0 clean build zip
To use library you should place libvlc dll files into the same folder as your program. See sample from 'trunk/samples' directory in the sources package.

Your opinion and feedback is more than greatly appreciated.

ivhorn
New Cone
New Cone
Posts: 2
Joined: 07 May 2009 16:40

Re: libvlcnet - .NET library based on libvlc

Postby ivhorn » 08 May 2009 10:26

Hi elwood,

I'm making a mediacenter application and started using your wrapper to integrate vlc player in a windows form control, inside a wpf window.
Compared to some other wrappers I've found more stability and more functionalities working, but I think it lacks in the possibility to start playbacks with custom options.
I need to start player with different settings according to given mediafile type, without destroying the control.
To do this I've modified the wrapper adding a method to reinitialize the player with a given set of options before each playback, but when I call this method I receive warnings about uncorrect player disposing.
Is this a correct workaround or could it rise some memory or stability problems?
Have you planned to add something similar or is there already a method that I missed to try?

Good work
Thanks

elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

Re: libvlcnet - .NET library based on libvlc

Postby elwood » 10 May 2009 17:05

Well, you can copy User Control from dz.mediaplayer.vlc.winforms library and rename it into yours, and then you can try to modify its initialization mechanism. For example, it is possible to add new method like Reinitialize() which will release old VlcPlayer instance and create new with new settings. If it will cause any problems, write here. Btw, can I ask you for sample settings set you need ?
//
PS I met some problems with reinitialization of vlclib earlier. Plugins was not detected on recreating VlcMediaLibraryFactory with different settings. I think it is feature of libvlc, so I recommend to avoid multiple initializations.

ivhorn
New Cone
New Cone
Posts: 2
Joined: 07 May 2009 16:40

Re: libvlcnet - .NET library based on libvlc

Postby ivhorn » 12 May 2009 15:17

It's exactly what I did: I added a Reinitialize method, as you can see below

Code: Select all

public void ReInitialize(string[] options) { // VLC objects initialization mediaLibraryFactory = new VlcMediaLibraryFactory(options); player = mediaLibraryFactory.CreatePlayer(new PlayerOutput(vlcWindowControl.Window)); // Subscribe to events VlcPlayerEventsReceiver receiver = new VlcPlayerEventsReceiver(); receiver.EndReached += endReachedEventHandler; receiver.PositionChanged += positionChangedEventHandler; player.EventsReceivers.Add(receiver); }
What I wish to do is playing video files with the following options:
"--aspect-ratio=16:9"
"--fullscreen"
"--file-caching=3000"

and music files with the following ones (for example):
"--no-fullscreen"
"--audio-visual=goom"
"--file-caching=300"

While debugging with visual studio no problem seems to be present;
but when I do the same operations in the target machine the player often hangs during reinitialization, forcing me to close application.

I saw that in other wrappers there is the possibility to specify playing options together with the name of the file to be reproduced, in the Play method, so I was wondering if there could be another way to do this.
Anyway for the moment I just included the first set of options in the Initialize() method, preferring not to do multiple initializations (sacrifying audio visual effects with mp3s)

thanks

rzar
New Cone
New Cone
Posts: 8
Joined: 13 May 2009 13:54

Re: libvlcnet - .NET library based on libvlc

Postby rzar » 13 May 2009 14:32

Hi.

You should dispose the factory and the player.
Maybe the problem is in the clarity check.
This check throws exception if factory or player not disposed.

Code: Select all

// Your code should look like this now: if (mediaLibraryFactory != null) { if (player != null) { player.Dispose(); } mediaLibraryFactory.Dispose(); } mediaLibraryFactory = new VlcMediaLibraryFactory(options); player = mediaLibraryFactory.CreatePlayer(new PlayerOutput(vlcWindowControl.Window)); // etc.
Best regards, RZ.

XXXLange
New Cone
New Cone
Posts: 3
Joined: 11 May 2009 18:08

Re: libvlcnet - .NET library based on libvlc

Postby XXXLange » 13 May 2009 19:30

Really great work!! Just some question to start: how did you manage the fullscreen mode? I've looked for it in classes and their properties and methods but I found nothing about it. Is there a way to see how to use your objects... for example DZ.MediaPlayer.Vlc.VlcMediaLibraryFactory needs a string array but what I should put in it? ...an initialized but empty array it doesn't work. However thanks for your useful efforts!

elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

Re: libvlcnet - .NET library based on libvlc

Postby elwood » 14 May 2009 12:10

Fullscreen mode is not implemented now, but you can set your window according to your screen width and height.
For initialization strings you can try code like from VlcPlayerControl:

Code: Select all

// VLC objects initialization mediaLibraryFactory = new VlcMediaLibraryFactory(new string[] { "--ignore-config", "--plugin-path", Path.Combine(getStartupPath(), "plugins") });
Dont forget to put plugins into directory specified.

XXXLange
New Cone
New Cone
Posts: 3
Joined: 11 May 2009 18:08

Re: libvlcnet - .NET library based on libvlc

Postby XXXLange » 14 May 2009 18:43

Thanks for answering. So the array contains the starting params of vlc if I've understood correctly, but at moment I was not able to use it yet.
Just a fast try, but it doesn't work.

Code: Select all

string v = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Substring(6) + "\\plugins"; DZ.MediaPlayer.Vlc.VlcMediaLibraryFactory vlc = new VlcMediaLibraryFactory(new string[]{ "--ignore-config", "--plugin-path", v })
.
I'll try it again quietly later.
About fullscreen I should say that the fullscreen is essential for what I have in mind (a mouse oriented wrapper).
At this time I've implemented the fullscreen mode "bypassing" the auto-fullscreen of libvlc (I've used a free dll - Gma.UserActivityMonitor.dll - which allows me to capture the mouse events when my program is not focused or active), but my problem now is that I always lose a lot of time looking for public methods of libvlc.
So maybe you could help me leading me to a place where there's a list of its functions so that I coud import those ones I need, 'cause I can't find it anywhere... yet! Anyway thanks and really great job!

Shinjin
New Cone
New Cone
Posts: 6
Joined: 29 Sep 2007 21:56

Re: libvlcnet - .NET library based on libvlc

Postby Shinjin » 23 May 2009 05:14

Ok I've finally found how to get a player open and working in VB.Net. Problem I'm now finding is that I can't seem to figure out how to pass DVD navigation commands. I got it to play, but cant get it past the menu, is there a way around this?

rzar
New Cone
New Cone
Posts: 8
Joined: 13 May 2009 13:54

Re: libvlcnet - .NET library based on libvlc

Postby rzar » 26 May 2009 16:23

Ok I've finally found how to get a player open and working in VB.Net. Problem I'm now finding is that I can't seem to figure out how to pass DVD navigation commands. I got it to play, but cant get it past the menu, is there a way around this?
Unfortunately this is not currently implemented. I think this is possible. We will implement this in the near future.

Anyway you always can modify source code.
I think you can modify "Player.cs/VlcMediaPlayerInternal.cs" to add methods like NextChapter/PrevChapter.
These methods should call internal vlc functions:

Code: Select all

void libvlc_media_player_set_chapter(libvlc_media_player_t *, int, libvlc_exception_t *) - Set movie chapter. int libvlc_media_player_get_chapter(libvlc_media_player_t *, libvlc_exception_t *) - Get movie chapter. int libvlc_media_player_get_chapter_count(libvlc_media_player_t *, libvlc_exception_t *) - Get movie chapter count. ........ void libvlc_media_player_previous_chapter (libvlc_media_player_t *, libvlc_exception_t *) - Set previous chapter. void libvlc_media_player_next_chapter (libvlc_media_player_t *, libvlc_exception_t *) - Set next chapter.
All dll imports located here "LibVlcInterop.cs".
You can find more documentation about these functions here: http://www.videolan.org/developers/vlc/ ... layer.html

wesley Chou
New Cone
New Cone
Posts: 3
Joined: 27 May 2009 04:21

Re: libvlcnet - .NET library based on libvlc

Postby wesley Chou » 27 May 2009 16:53

Hi
I try to modify the code to play video from media server (via rtsp or rtp), but still have no idea, is anyone kindly give me some suggestions?
thanks.

best regards
wesley

elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

Re: libvlcnet - .NET library based on libvlc

Postby elwood » 28 May 2009 20:55

You can look at the VlcMediaInternal class which "translates" the input parameters into VLC's MRL and calls

Code: Select all

LibVlcInterop.libvlc_media_add_option(descriptor, option, ref exc);
to specify the media source for playing. If you need advanced MRLs, you can change the SetOutput method and test it. Existing method has limitations and you can improve this by experimenting with various MRLs.

wesley Chou
New Cone
New Cone
Posts: 3
Joined: 27 May 2009 04:21

Re: libvlcnet - .NET library based on libvlc

Postby wesley Chou » 02 Jun 2009 11:15

hi elwood
thanks your reply, I have another quesiton
I have one media server(eg helix server, server name is superfly) , if I assign the MRL(eg rtsp://superfly/test.mp4) is that mean play video which send from media server? , do I still need to modify setoutput method ? because I read the code it seems try to export to file or stream, am I correct?

sorry about my poor English

regards
wesley

wesley Chou
New Cone
New Cone
Posts: 3
Joined: 27 May 2009 04:21

Re: libvlcnet - .NET library based on libvlc

Postby wesley Chou » 04 Jun 2009 09:49

hi
I am already resolve the problem, thanks

oppio
New Cone
New Cone
Posts: 4
Joined: 05 May 2009 16:31

Re: libvlcnet - .NET library based on libvlc

Postby oppio » 10 Jun 2009 16:26

Hi,

I'm in the same situation described by ivhorn, i.e. I need to re-initialize the player in order to pass different command line parameters. I have modified the VlcPlayerControl code so that the VlcDeployment is only initialized once, and mediaLibraryFactory and player are disposed and re-initialized when needed:

Code: Select all

public void Initialize(string[] options) { if (!isInitialized) { VlcDeployment deployment = VlcDeployment.Default; if (!deployment.CheckVlcLibraryExistence(true, false)) { if (logger.IsInfoEnabled) { logger.Info("Unable to find installed vlc library. Starting installing from zip archive."); } deployment.Install(false, true, false, false); if (logger.IsInfoEnabled) { logger.Info("Installed."); } } isInitialized = true; } ReInitialize(options); } public void ReInitialize(string[] options) { if (mediaLibraryFactory != null) { if (player != null) player.Dispose(); mediaLibraryFactory.Dispose(); } // VLC objects initialization mediaLibraryFactory = new VlcMediaLibraryFactory(options); player = mediaLibraryFactory.CreatePlayer(new PlayerOutput(vlcWindowControl.Window)); // Subscribe to events VlcPlayerEventsReceiver receiver = new VlcPlayerEventsReceiver(); receiver.EndReached += endReachedEventHandler; receiver.PositionChanged += positionChangedEventHandler; player.EventsReceivers.Add(receiver); }
This solution introduced a new problem getVlcObjectsByName in VlcPlayer, the the Marshal.PtrToStructure(IntPtr, object) method is invoked, as it randomly causes an ExecutionEngineException:

Code: Select all

private static void getVlcObjectsByName(IntPtr pObject, string objectNameToSearch, ICollection<int> idList) { try { vlc_common_members common_members = (vlc_common_members)Marshal.PtrToStructure(pObject, typeof(vlc_common_members)); if (common_members.ObjectName == objectNameToSearch) { idList.Add(common_members.i_object_id); } // libvlc_list_t childs = LibVlcInterop.__vlc_list_children(pObject); foreach (libvlc_value_t val in childs.values) { getVlcObjectsByName(val.p_object, objectNameToSearch, idList); LibVlcInterop.__vlc_object_release(val.p_object); } } catch (ExecutionEngineException eee) { Console.WriteLine(eee.ToString()); } }
Furthermore, the application gets terminated even if I try to catch the exception. This behaviour is quite random and I'm not sure what the problem is, if it's a problem of libvlc corrupting memory, or caused by .NET.
Looking at the code, I can see that getVlcObjectsByName is called to store objects named "elwood_adjust" into some List for loaded filters. I wonder what's that filter about, if I can avoid loading it and thus avoid calling getVlcObjectsByName at all.


Any input might be helpful :)

Valerio

oppio
New Cone
New Cone
Posts: 4
Joined: 05 May 2009 16:31

Re: libvlcnet - .NET library based on libvlc

Postby oppio » 02 Jul 2009 16:01

Hi,


I'm trying to use libvlcnet to playback a video and display audio visualizations too. For this reason, I added the following command line parameters:
--audio-visual=visual
--effect-list=scope

no matter what the effect-list is, "visual" will always cause the application to crash with a win32 exception that is impossible to catch, while "goom" just works fine, with the goom output overlayed on the normal video output.
If I run VLC from dos prompt using the exact same command line parameters, it works fine with both visual and goom, always displaying the audio visualization in a separate window.

I assume that when I run VLC from my C# application using libvlcnet, it "tries" to fit both the video output and the audio visualization output on the same picture box, i.e. not in a separate window. Is there any way to change this behaviour in order to get the audio visualization output on another windows or picture box?


Thanks in advance :)

mihir
New Cone
New Cone
Posts: 1
Joined: 07 Aug 2009 11:35

Re: libvlcnet - .NET library based on libvlc

Postby mihir » 07 Aug 2009 11:39

can someone please provice me simple code to just play audio files (specially .ogg) using this library. i don't want any other feature.

thanks in advance.

mihir

tigerman81
New Cone
New Cone
Posts: 1
Joined: 26 Aug 2009 11:17

Re: libvlcnet - .NET library based on libvlc

Postby tigerman81 » 26 Aug 2009 11:54

can someone please provice me simple code to just play audio files (specially .ogg) using this library. i don't want any other feature.

thanks in advance.

mihir
Depending on the way you would like to build the application here is one way you can do it. Remember you'll have to add references to the 4 .dll files which come with libvlcnet. You'll also need to have the libvlc.zip file in the same directory as your program executable. If you are using Visual Studio you can add it as an existing item to your project and then direct it to copy to the program directory on build.


using DZ.MediaPlayer.IO;
using DZ.MediaPlayer.Vlc.WindowsForms;


VlcPlayerControl vlcPlayerControl = new VlcPlayerControl();

vlcPlayerControl.Initialize();

vlcPlayerControl.Visible = false;

// Note the second parameter is a string which represents the path to the file you want to play.
// The easiest way to feed this parameter in is with an OpenFileDialog, in which case you could
// use: openFileDialog.FileName after you've opened the file dialog and selected the file you want
// to play.
MediaInput input = new MediaInput(MediaInputType.File, "path to the file you want to play as a string");

vlcPlayerControl.Play( input );

That about all there is to it. Of course the above code is VERY simplistic. As it is above it would only open one file and start playing immediately and then stop when
it reached the end of the file. Obviously if you were including this as part of a Form application you could add various controls such as buttons to Pause, Play, Stop
the file using the various methods of the VlcMediaPlayer.

Hopefully this makes sense to you. If you need a little more detailed explanation let me know.

mascatul
New Cone
New Cone
Posts: 1
Joined: 11 Oct 2009 23:23

Re: libvlcnet - .NET library based on libvlc

Postby mascatul » 11 Oct 2009 23:49

Guys this doesn't work for me my code looks like this:

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; using DZ.MediaPlayer.Io; using DZ.MediaPlayer.Vlc.WindowsForms; using DZ.MediaPlayer.Common; using DZ.MediaPlayer.Vlc.Windows; namespace test4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { VlcPlayerControl vlc = new VlcPlayerControl(); vlc.Initialize(); vlc.Visible = true; MediaInput input = new MediaInput(MediaInputType.File, "c:\\1.avi"); vlc.Play(input); } } }
I already included the zip in the folder and added the references but i have this error at initialization "{"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"}" any of you have any ideea.
Thanks in advance!

elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

Re: libvlcnet - .NET library based on libvlc

Postby elwood » 19 Oct 2009 12:59

Are you using x64 OS ?

Idsa
Blank Cone
Blank Cone
Posts: 78
Joined: 22 Oct 2009 10:59

Re: libvlcnet - .NET library based on libvlc

Postby Idsa » 22 Oct 2009 11:11

elwood, please tell me why PlayerOutput is marked readonly, although VlcMediaInternal contains method SetOutput? Is it right that for output changing I should create new player instance?

Idsa
Blank Cone
Blank Cone
Posts: 78
Joined: 22 Oct 2009 10:59

Re: libvlcnet - .NET library based on libvlc

Postby Idsa » 23 Oct 2009 08:06

I have a very strange problem with VLC. I am running the .NET form with libvlcnet control under VB6 (for compatibility reasons) and it doesn't work: I get an exception "Timeout waiting required state" at VlcPlayer.waitForMediaState (stateRequired = Play). But if I run this application from VS 2008 (setting my VB6 application as start up application) - it works. Do you know any reasons for that?

elwood
Blank Cone
Blank Cone
Posts: 24
Joined: 04 Oct 2008 15:28

Re: libvlcnet - .NET library based on libvlc

Postby elwood » 25 Oct 2009 11:37

> elwood, please tell me why PlayerOutput is marked readonly, although VlcMediaInternal contains method SetOutput? Is it right that for output changing I should create new player instance?
Yes, you should get a new VlcPlayer instance to change the PlayerOutput. We implemented it because libvlc doesn't allow to change the output of created VLCMedia dynamically. And if you change the VlcPlayer's output, it will be applied in the next or after next playing media only. That behavior is not transparent for developers who are using the library, and we decided to disable feature of changing PlayerOutput in VlcPlayer's context. Now VlcPlayer takes the instance of PlayerOutput in constructor.

> I have a very strange problem with VLC. I am running the .NET form with libvlcnet control under VB6 (for compatibility reasons) and it doesn't work: I get an exception "Timeout waiting required state" at VlcPlayer.waitForMediaState (stateRequired = Play). But if I run this application from VS 2008 (setting my VB6 application as start up application) - it works. Do you know any reasons for that?
I don't understand how do you use this control with VB6 ? Or it is VB .NET ?

Idsa
Blank Cone
Blank Cone
Posts: 78
Joined: 22 Oct 2009 10:59

Re: libvlcnet - .NET library based on libvlc

Postby Idsa » 26 Oct 2009 06:05

>>Yes, you should get a new VlcPlayer instance to change the PlayerOutput. We implemented it because libvlc doesn't allow to change the output of created VLCMedia dynamically. And if you change the VlcPlayer's output, it will be applied in the next or after next playing media only. That behavior is not transparent for developers who are using the library, and we decided to disable feature of changing PlayerOutput in VlcPlayer's context. Now VlcPlayer takes the instance of PlayerOutput in constructor.

Ok. Thank you for clarification.

>>I don't understand how do you use this control with VB6 ? Or it is VB .NET ?

If it were VB.NET I would be much happier (although C# would be more wishful for me). I have to use .NET forms from VB6 using COM for the reason of backward compatibility. As I have found out the described situation is VB6 debuuger bug (but I'm still not sure) and without debugger application works well. So... it would add to me some more problems during debugging but finally it won't influence on my application (I hope :) ).

Idsa
Blank Cone
Blank Cone
Posts: 78
Joined: 22 Oct 2009 10:59

Re: libvlcnet - .NET library based on libvlc

Postby Idsa » 27 Oct 2009 06:35

elwood, when PlayerOutput.Files should be saved to disk? At Stop or realtime? It seems they are not saved at all.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 19 guests