11

i'm trying to control the VLC Media Player from C#. I tried getting a handle on the window with the FindWindow() command from .Net but as i found out the name of the window changes every time a file is played. The biggest problem i have is sending wm_commands to vlc..This approach worked with Winamp and Windows Media Player but with VLC it appears that it won't work.

I read that VLC can be controlled from a browser but i don't whant that...i've seen in it's settings that it has some hot keys that can be called..but they can be changed and if i call them from my code somehow...and the user changes them..bummer...

i'm a little bit stuck..any help would be fantastic... Sorin

Sorin Antohi
  • 6,145
  • 9
  • 45
  • 71
  • What is your goal here? Drive VLC? Integrate into an application? – Sam Saffron Apr 24 '09 at 13:27
  • hello, i want to control VLC..like pushing a stop button in my app and the VLC player stops. The VLC is not integrated in my app..my app will be like a remote control... libvlc an libvlc-sharp look like a solution..i have to look in depth.. – Sorin Antohi Apr 24 '09 at 13:43
  • hello sambo, the idea was to control(drive) VLC, not integrating it in another app. VLC should run normally in windows and receive WM commands from a C# app. – Sorin Antohi May 14 '09 at 05:39

6 Answers6

9

I have some code that is able to control it using sockets on the RC interface. This worked to a degree but has a lot of quirks. go to full screen seems to do nothing for a few seconds after play is invoked. Overall it sort of works.

The other options are:

Write a DirectDraw filter (very hard) but once this is done VLC can be used instead of or in conjunction with FFMPEG. Existing code that drives media player could use vlc.

Write an interop wrapper for libvlc, recently the VLC team split out libvlccore from libvlc so to the best of my knowledge all the interop is out of date. Once you write a wrapper you could embed vlc in a windows app. (if you need to support x64 you need to compile these libs under x64.

Look through the VLC code and find out if there is a way to send these windows messages.

EDIT This appears to have come out this week.

Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
  • This technique requires user to start VLC with some flags (via command line correct me if I am wrong). I am also facing this problem what if my user has started VLC from windows. I can't ask my user to enter the RC mode. Doesn't VLC provide any other way to control itself? Like COM interface in windows media player or iTunes? – MaX Jul 12 '12 at 14:14
3

As Eoin mentioned, libvlc can be used to interact with VLC. As a C# user, you may want to try the .NET bindings offered by the libvlc-sharp project.

Edit: Seems like this project has not been maintained for years. I will leave the link anyway, in case you wish to take a look at it and maybe put some of its source to use.

Tormod Fjeldskår
  • 5,952
  • 1
  • 29
  • 47
  • 1
    this library was out of date 3 days ago – Sam Saffron Apr 24 '09 at 13:34
  • No I think Sam means that since the team split the codebase into seperate libraries, the existing interop wrapper is no longer functional. You would need a new wrapper for the functions in the libvlc library. – Anonymous Type Jan 25 '11 at 04:09
  • Also, it doesn't appear to handle video through the API (not sure if this is a requirement). From the read-me: "At the moment only the audio portion of the api is finished.". As a side note, you may want to check out this post: http://stackoverflow.com/questions/584147/vlc-server-communication-with-net-c – Aaron Newton Mar 10 '11 at 23:44
2

Have you looked at libvlc

You might be able to wrap that up in a library and interact with VLC through that.

Sylvain Rodrigue
  • 4,751
  • 5
  • 53
  • 67
Eoin Campbell
  • 43,500
  • 17
  • 101
  • 157
1

How use libvlc in C++ http://unick-soft.ru/art/files/libvlcProject.zip I think, use libvlc in C# very similar.

1

If what you are trying to do is control a previously running executable, check out the Process class to enumerate through all the current processes or do it by name. Check the executable to match vlc.exe. You can then get a handle to the main window and do some P/Invoke to send messages as you are doing with your other executables. This is obviously riddled with potential problems such as if the there are changes to the keyboard shotcuts.

Erich Mirabal
  • 9,860
  • 3
  • 34
  • 39
0

There's also the rc interface and even a telnet one: http://wiki.videolan.org/Console

However, I'd prefer libvlc if possible.

Mark
  • 6,269
  • 2
  • 35
  • 34