More libvlc in C#

All you've ever wanted to know about the ActiveX, Mozilla plugins, the web interface and various PHP extensions
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 » 12 Jan 2007 10:31

The Test.html file has been renamed on the Wiki to .Net_Test.html.
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.

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

Postby divx118 » 12 Jan 2007 18:24

:D Thanks Tappen I will try it over the weekend

EDIT: I coudn't wait so I tried it.
my steps:
Build the dll file and create the snk no problem
copied both files to my vlc installation folder next to the libvlc.dll in
F:\Video tools\VLC\

Then i run regasm "F:\Video tools\VLC\VLanControl.dll" /codebase Types registered successfully

copied the Test.html to the folder and ran it. The object loads but i get no video just a white background (btw edited the html file to play a video of mine)

Update: It works for the no videopart. I added an onload event in the body tag to start playing the video. And that worked :D

I am running out of luck again I can't get it to show up in media center it just gives me a red cross, maybe it is because it is written in .Net 2 and media center is based on .NET 1.
In ie7 it just works fine.




PS I am using ie7 on a windowsXP media center machine.
Thanks alot for making this dll compatible with javascript :D


Maurice

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

Postby osmanosman » 15 Jan 2007 10:51

You are the best Tappen :P

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

Sizing Window to Native Video Size

Postby sgross » 15 Jan 2007 23:02

Tappen, Thank you for all your help!

I still have an issue with the sizing though and some of the properties...

I try sizing the window by the following code:

Code: Select all

VideoCtrlDataSet.StreamSourcesRow myStream; public ViewVideo(VideoCtrlDataSet.StreamSourcesRow aStream) { InitializeComponent(); myStream = aStream; } private void ViewVideo_Load(object sender, EventArgs e) { vlcVideo.AddToPlayList("udp://@" + myStream.MulticastIP + ":" + myStream.Port, "", null); vlcVideo.Play(); //MessageBox.Show(vlcVideo.VideoSize.Height.ToString()); this.Size = vlcVideo.VideoSize; this.Text = "Height: " + this.Size.Height + " Width: " + this.Size.Width; }


When this is run, it sizes the window to 0,0. If I uncomment the MessegeBox, the Text in the MessageBox is 0. Then the window loads the correct value (although it's a little wider than it should be, but I can deal with that).

I would think it cause the video hasn't fully "started to play" so it still reads the size as 0,0. But when stepping through in the debugger, it shows vlcVideo.VideoSize.Height as the right size, but just does not assign it to the local VideoSize.

Any ideas?

Also on another note, the inital properties

Code: Select all

this.vlcVideo.AllowVideoAdjustments = false; this.vlcVideo.Volume = 50;
cause the "trying to read from protected memory issue as if it's not being initialized correctly. Once I comment these lines out, it works fine.

Please let me know if you have ideas about either of these topics. Thank you.

Ncd
New Cone
New Cone
Posts: 1
Joined: 16 Jan 2007 15:39

Howto initalize NativeLibVlc

Postby Ncd » 16 Jan 2007 21:33

be sure you call Initialize() on the NativeLibVlc object before making any other calls to it.
I'm probably missing something basic here, but could anyone explain how to initalize the NativeLibVlc-object? Compiling the DLL is no problem, I can add the user control to a form, but where to go next?

Keep reading about OnLoad etc, but since the NativeLibVlc object appear to be protected, how do I initialize it?

Perhaps someone would be as kind as to post a working example?

zbe
New Cone
New Cone
Posts: 3
Joined: 28 Dec 2006 12:48

Postby zbe » 16 Jan 2007 23:15

Tappen,

have you seen that :

http://wiki.videolan.org/MediaControlAPI#Full_API

How can you get informations about current playlist ?

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

Postby Tappen » 17 Jan 2007 00:16

Note: The .Net_Test.html file loads a file from my local hard-disk named Kiki.mpg as its sample. This obviously won't work for anyone but me so be sure to edit it before trying. Just change the filename to a short video of your own.

I just updated the .Net Wiki Page with a new VlcUserControl.cs file that makes all the Vlc native properties non-browsable so the control will work better in Design mode. Sorry about that, I created the control dynamically in my own code and never tried actually dropping it on a Form.

Ncd, if you built the whole DLL and dropped a VlcUserControl on your form or Web Page then VlcUserControl does the initialization of NativeLibVlc for you in its OnLoad. The only thing you need to worry about is not adding things to the playlist until your Form's OnLoad or later. The ambiguity is that I had the idea some people would only use the NativeLibVlc class and others would use the whole VlcUserControl and my documentation isn't too clear at explaining which case it's talking about.

sgross and others, your problem is that VLC is asynchronous. You might think you're loading the video when you call AddToPlaylist but actually this happens some time later in another thread within VLC. You can see in the test html file that I poll every second waiting for the State of the control to become Playing before I start playing around with the options, like AllowVideoAdjustments. You need to do the same in C# and have an interval timer object waiting for the State to hit Playing before re-sizing, etc. Sorry but there's no way I can force Vlc to load and start playing immediately, since it might just timeout and fail to load completely, so there's no way to examine the video properties before it starts Playing some unknown time in the future.

One enhancement I'm thinking about adding for my own piece of mind is to implement a callback when the State variable changes. I figured out how to do callbacks with the Now Playing event (which I use to show ShoutCast internet radio tracks, btw) so it shouldn't be that hard.

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

Postby osmanosman » 18 Jan 2007 11:12

a litle question
.net interface using this settings file
C:\Documents and Settings\user\Application Data\vlc\vlcrc

Is there any way to hinder using this file or change file name?

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

Call Back Functions...

Postby sgross » 18 Jan 2007 16:27

Tappen, That would be great if there was just a call back. I'll use the timer for now. I figured that is what was going on.

On another note,
Sometimes if I load multiple VLC windows and one is overlapped, the bottom window goes black. for example, If I have 5 windows open and the sixth loads on top of the 1st, the first would go black, but I can drag that 6th windows around and the other windows continue to play correctly.

Any ideas? Is there a better forum for this question?

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

Postby osmanosman » 18 Jan 2007 22:16

use "no-overlay" for black screen

Code: Select all

string[] initOptions = { "vlc", "--no-one-instance", "--no-overlay", "--no-snapshot-preview", "--no-drop-late-frames", "--disable-screensaver" };

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

I still can't get VLanControl working in VB.NET 2005

Postby nkarnold » 19 Jan 2007 11:39

Can anyone post some good example code (not pseudo). of using the Control.

I've already tried the authors suggestion of making the parent of the control, the form. No joy, just lots of exception messages.

Keep up the good work.


Fingers crossed for some VB.NET 2005 example.

Cheers

N

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

Postby Tappen » 20 Jan 2007 04:01

Sorry I don't do VB.NET, but in C# you'd create a new Windows Application project named Foo and save it. Then copy VLanControl.dll, VLanControl.pdb, libvlc.dll, and the plugins directory to the Foo\Foo\bin\Debug directory of the new project. Add a reference to VLanControl.dll in the new project by Browsing to the same bin\Debug directory.

In Form1.cs of the new project you could put

Code: Select all

public partial class Form1 : Form { VLanControl.VlcUserControl vlc = new VLanControl.VlcUserControl(); Timer timer; bool sizingNeeded; public Form1() { InitializeComponent(); vlc.Parent = this; vlc.Dock = DockStyle.Fill; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.sizingNeeded = true; this.vlc.AddAndPlay(@"YourMediaFile.ext", ""); this.timer = new Timer(this.components); this.timer.Interval = 500; this.timer.Tick += timer_Tick; this.timer.Start(); } void timer_Tick(object sender, EventArgs e) { if(this.sizingNeeded && (this.vlc.State == VLanControl.PlayerState.Playing)) { this.ClientSize = this.vlc.VideoSize; this.sizingNeeded = false; } } }
Change the name of the media file and you have yourself a simple player application. This doesn't Dispose of things properly but it's the smallest useful project I can think of.

eiden
New Cone
New Cone
Posts: 3
Joined: 20 Jan 2007 15:20
Location: Norway

How can I access the messages from C# ?

Postby eiden » 20 Jan 2007 15:27

Tappen, thanks for the excellent work!

I have a question.

How can I access the information that is displayed in the messages window (View -> Messages) from C#?

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

Postby Tappen » 20 Jan 2007 19:35

The short answer is to wait for me to write the code, or look at the ActiveX source code and move that to C# yourself. I haven't looked into Messages.

eiden
New Cone
New Cone
Posts: 3
Joined: 20 Jan 2007 15:20
Location: Norway

Postby eiden » 20 Jan 2007 19:39

The short answer is to wait for me to write the code, or look at the ActiveX source code and move that to C# yourself. I haven't looked into Messages.
Ok. Thanks for the answer :) Now I know where to look.

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

VB.NET Example

Postby nkarnold » 21 Jan 2007 01:17

Thanks for that, I've managed to get it going in VB.NET now.. I didn't realise that the plugins directory had to be under directory where the compiled binary was run from (I saw the --plugins path in your code)

Any way. For those VB.NET'rs.. below is the example
Add vlancontrol to your vb.net project as a reference

Code: Select all

Private Sub PlayVideoFile() Dim Video As New VLanControl.VlcUserControl Dim sFilename As String, sTitle As String Dim Options(2) As String Video.Parent = Me Video.Dock = DockStyle.Fill sFilename = "dvdsimple://E:@1:2" ' Replace this with your video file, stream, dvd path etc.. sTitle = "My Video File" Options(0) = ":volume=75" ' These can be any of the VLC options, replace as needed Options(1) = ":audio-track=0" Video.ClearPlayList() Video.AddToPlayList(sFilename, sTitle, Options) Video.Play() ' At this point, you may want to start a timer or a thread and monitor ' video.isplaying ' video.time End Sub

retevenard
New Cone
New Cone
Posts: 8
Joined: 20 Jan 2006 16:01

Postby retevenard » 08 Feb 2007 17:01

Hi,

Maybe it's a stupid question but where I can find the file VLanControl.dll.

I didn't see a link to download this file on the http://wiki.videolan.org/.Net_Interface_to_VLC

Thanks for your answer.

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

Postby sgross » 08 Feb 2007 17:09

Hi,

Maybe it's a stupid question but where I can find the file VLanControl.dll.

I didn't see a link to download this file on the http://wiki.videolan.org/.Net_Interface_to_VLC

Thanks for your answer.
You have to copy all the code into Visual Studio and then compile the project. This generates the VLanControl.dll that you can then add to the toolbox.

retevenard
New Cone
New Cone
Posts: 8
Joined: 20 Jan 2006 16:01

Postby retevenard » 09 Feb 2007 09:05

Thanks for your answer but someone can send me this dll to my email renaud_sadus@hotmail.com.

Thanks in advance.

GJ
New Cone
New Cone
Posts: 2
Joined: 15 Feb 2007 13:31

Postby GJ » 15 Feb 2007 14:12

Hi,

First of all, thanks for the VLanControl.dll.
As I'm quite new at programming it really helps me a lot.
Tappen,

have you seen that :

http://wiki.videolan.org/MediaControlAPI#Full_API

How can you get informations about current playlist ?
As zbe I'm wondering, how I can get the playlist.

I could not figure out.
I'm using the VlcControl.
Added some files.
Video is playing, and I tried to get the playlist with "vlc.Programs()", but it keeps returning an empty array.

Can anybody please give me a hint, how I can get the playlist?

Thanks

Cooldream
Blank Cone
Blank Cone
Posts: 12
Joined: 08 Sep 2006 09:55

Postby Cooldream » 16 Feb 2007 13:34

Hello,
I don't know the C#.
I use VB6 and I could try VB.net 2005.
Could someone give me a complete exemple in VB6 or VB.net (the code and the VLanControl.dll compiled) ?

Thanks...

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

Postby sgross » 19 Feb 2007 16:14

Hello,
I don't know the C#.
I use VB6 and I could try VB.net 2005.
Could someone give me a complete exemple in VB6 or VB.net (the code and the VLanControl.dll compiled) ?

Thanks...
Sorry, I don't know normally work in VB and unfortunately do not have the time to convert it for you.

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

Disposing of things properly...

Postby sgross » 11 Apr 2007 04:59

Sorry I don't do VB.NET, but in C# you'd create a new Windows Application project named Foo and save it. Then copy VLanControl.dll, VLanControl.pdb, libvlc.dll, and the plugins directory to the Foo\Foo\bin\Debug directory of the new project. Add a reference to VLanControl.dll in the new project by Browsing to the same bin\Debug directory.

In Form1.cs of the new project you could put

Code: Select all

public partial class Form1 : Form { VLanControl.VlcUserControl vlc = new VLanControl.VlcUserControl(); Timer timer; bool sizingNeeded; public Form1() { InitializeComponent(); vlc.Parent = this; vlc.Dock = DockStyle.Fill; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.sizingNeeded = true; this.vlc.AddAndPlay(@"YourMediaFile.ext", ""); this.timer = new Timer(this.components); this.timer.Interval = 500; this.timer.Tick += timer_Tick; this.timer.Start(); } void timer_Tick(object sender, EventArgs e) { if(this.sizingNeeded && (this.vlc.State == VLanControl.PlayerState.Playing)) { this.ClientSize = this.vlc.VideoSize; this.sizingNeeded = false; } } }
Change the name of the media file and you have yourself a simple player application. This doesn't Dispose of things properly but it's the smallest useful project I can think of.
Could someone post exactly how to "Dispose of things properly"? I want to make sure I'm doing things correctly.

Thank you in advance

dl0haus
Blank Cone
Blank Cone
Posts: 11
Joined: 20 Feb 2007 02:09

C# downloader...

Postby dl0haus » 12 Apr 2007 19:35

I'm curious how I might go about accessing VLC's live stream downloading capability through the DLL? I'm writing a C# application that needs this ability... I wrote a custom implementation of MMS (a pain) and thought I'd try out the DLL.

Basically I have live streams at a designated address that can be MMS/RTSP/HTTP and I want to save them to a local file. The VLC player has this functionality but I was wanting to accomplish the same thing without playing the files locally, just doing a raw download to ASF.

Any ideas or samples?
Thanks,
D

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

Re: C# downloader...

Postby sgross » 12 Apr 2007 19:50

I'm curious how I might go about accessing VLC's live stream downloading capability through the DLL? I'm writing a C# application that needs this ability... I wrote a custom implementation of MMS (a pain) and thought I'd try out the DLL.

Basically I have live streams at a designated address that can be MMS/RTSP/HTTP and I want to save them to a local file. The VLC player has this functionality but I was wanting to accomplish the same thing without playing the files locally, just doing a raw download to ASF.

Any ideas or samples?
Thanks,
D
If you follow the example I quoted in my last post, you just need the correct string the following line...

Code: Select all

this.vlc.AddAndPlay(@"YourMediaFile.ext", "");
The simple way to create the correct string is to load VLC and play the stream the way you want and use the string genereated in the Open Dialog box.

The string is in Advanced Options. That opens the correct stream. Then click on the Settings button and select your streaming options. This generates the "Stream Output MRL" When those two strings are correctly added to the AddandPlay command it should work.

Let me know how it turns out, I'm planning on doing something similar in a few weeks.


Return to “Web and scripting”

Who is online

Users browsing this forum: No registered users and 11 guests