PDA

View Full Version : MPC HC - Feature Requests: advanced API for complete control from another program


dimzon
31st January 2008, 18:30
Dear developers!
As i said before (http://forum.doom9.org/showthread.php?t=134263) i'm looking for API to control MPC from my HTPC application, written in C#. What I really need:

1) obtain notifications (playback started/completed)
2) now playing file info including properties, lenght and position
3) obtain list of avaluable audio tracks and current audio track
4) obtain list of avaluable subtitles and current subtitle
5) obtain chapter list
6) manipulate current playlist
7) turn subtitle by name/index (obtained from 3)
8) turn audio by name/index (obtained from 2)
9) get and set current audio delay
10) set current position

You can implement this via WM_COPYDATA or via NamedPipes or via HTTP.

:thanks:

Casimir666
31st January 2008, 19:59
Check you mailbox ;)

dimzon
1st February 2008, 15:13
Check you mailbox ;)
Hi!
Unfortunally I havn't Internet Connection at my home :mad: and I can't use MSM at my office. Oh, and my Inbox is 97% full. So why not just discuss this API into thread?

talking about implementation I think the best way will be to use STDIN/STDOUT and special command-line parameter, for example /SLAVE. In this case MPC will listen commands from STDIN and reply to STDOUT. For example I can propose such protocol

EXEC MPC.EXE /SLAVE
STDOUT: MPC, version XXX, bla-bla-bla
STDIN:CREATE PLAYLIST n // where n means playlist size
STDIN:fileName1.avi
STDIN:fileName2.avi
...
STDIN:fileNamen.avi
STDIN:PLAY x // where [B]x[X] means playlist position
STDOUT:PLAYBACK STARTED
STDOUT:fileName
STDIN:LIST AUDIO STREAMS
STDOUT:n m // where n means count, m means current stream
STDOUT:STREAM NAME 1
STDOUT:STREAM NAME 2
...
STDOUT:STREAM NAME n
STDIN: SET AUDIO STREAM [b]x[b]

etc...

What does You think?

Casimir666
1st February 2008, 19:06
I think the WM_COPYDATA will be easier. As argument you give me you app main windows handle :

Start : EXEC MPC.EXE /SLAVE 0x1000D1

Dialog message could then be a string starting with a code and the parameters :

Ex :
// After launch MPC -> Your App : code 1 follow by MPC window handle
1|0x120120

// Add to playlist Your App -> MPC : code 2 follow by filenames
2|filename1|filename2

...

Is it ok for you?

dimzon
4th February 2008, 14:35
I think yes, WM_COPYDATA is sutable too
by the way: to avoid any mistakes let's use UTF8 encoding for filenames etc.

Casimir666
10th February 2008, 12:29
It's not entirely finished, but i have a first release for mpc API downloadable from here : http://www.zshare.net/download/7381233e7c777c/

API test program is available on SF here :
http://mpc-hc.svn.sourceforge.net/viewvc/mpc-hc/trunk/src/apps/MPCTestAPI/


Currently available functions are :
1) obtain notifications (playback started/completed)
2) now playing file info including properties, lenght and position
6) manipulate current playlist (add, clear, start playing)
9) set current audio delay (no get yet)
10) set current position
+ Standard commands : open, play, pause, stop, close


For the "Get" functions how do you want to proceed? You send a cmd "Ask for XXX" and i return a notification with the value?
It's not possible to return data via WM_COPYDATA messages isn't it?

dimzon
11th February 2008, 13:22
It's not entirely finished, but i have a first release for mpc API downloadable from here : http://www.zshare.net/download/7381233e7c777c/

API test program is available on SF here :
http://mpc-hc.svn.sourceforge.net/viewvc/mpc-hc/trunk/src/apps/MPCTestAPI/


Currently available functions are :
1) obtain notifications (playback started/completed)
2) now playing file info including properties, lenght and position
6) manipulate current playlist (add, clear, start playing)
9) set current audio delay (no get yet)
10) set current position
+ Standard commands : open, play, pause, stop, close

Fine, i will check this asap



For the "Get" functions how do you want to proceed? You send a cmd "Ask for XXX" and i return a notification with the value?
It's not possible to return data via WM_COPYDATA messages isn't it?
Yes, it isn't possible. There are 2 ways to return value
1) if value is small (fits to 32bit signed integer) it's possible return it as LRESULT
2) send WM_COPYDATA as answer

dimzon
11th February 2008, 14:07
Hey, Casimir666 I found yet another way for "Get" functions
Actually we can use WM_GETTEXT (http://msdn2.microsoft.com/en-us/library/ms632627.aspx) to obtain data from MPC. So you just need to create special invisible window or control witch contains everything in XML form (and update it every time something changed). For example:

<mpc-info>
<current-file>C:\myvideo.avi<current-file>
<duration>01:21:57</duration>
<position>01:09:32</position>
<audio-delay-in-ms>0</audio-delay-in-ms>
<subtitle-delay-in-ms>0</subtitle-delay-in-ms>
<audio-track index="1" active="yes">AC3 Russian</audio-track>
<audio-track index="2">AC3 English</audio-track>
<show-subtitles>no</show-subtitles>
</mpc-info>

What do you think?

dimzon
11th February 2008, 16:11
what information I need asap:
private string[] audioTracks;
private string[] subtitles;
private int currentAudioTrack;
private int currentSubtitle;
private int audioDelay;
private int subtitleDelay;
private string[] playlist;
private int currentFile;
private string[] chapters;
private int currentChapter;

private TimeSpan duration;
private TimeSpan position;

Some ideas about playlist. Actually, even if you open one file will be created playlist. So I doesn't need current-file but i need complete playlist (array of full file pathes) and index of current file.

MatMaul
24th February 2008, 23:37
what about define a string model and send it by a WM_COPYDATA message ?

for example for a CMD_GETPLAYLIST :
current_file|nb_of_files|file1|file2|...

CMD_GETAUDIOTRACKS :
current_audio|nb_of_audio|audio1|audio2|...

CMD_GETSUBTRACKS :
sub_are_active|current_sub|nb_of_sub|sub1|sub2|...

I will try to implement something like that during the week.

Casimir666
25th February 2008, 08:24
Dimzon I'm terribly confused i realize i haven't respond to your questions, and i didn't works on you API for the last 2 weeks. MatMaul is now a member of mpc-hc and he can give you a hand for this :-)

I agree with him it's better to stay on wm_copy messages to communicate between both application. About you question on OSD : the actual implementation in mpc is far from perfect, and it have several problems :
- didn't works with all renderer
- on windowed vmr, OSD is set before resizing
- it's quite ugly

Maybe you can keep you OSD solution for the moment, and we will see later if we can do better osd than can be pilot remotly...

dimzon
26th February 2008, 12:24
Hi!
Actually obtaining information via WM_GETTEXT (http://forum.doom9.org/showpost.php?p=1098962&postcount=8) is much more easy to implement in both sides (MPC must update this invisible window and client don't need to catch to many different messages.

And some additional ideas (just ideas, what do you think)
1) How about to make MPC out-of-process COM server?
2) How about to split MPC into 2 parts. First part - mplayerc.dll will contain everything playback-related. Second part mplayerc.exe will be frontend.

MatMaul
26th February 2008, 16:09
sorry I don't know very well how to do with WM_GETTEXT and I began to do it yesterday with WM_COPYDATA.
here is my work :
http://www.etud.insa-toulouse.fr/~mvelten/bordel/mpc_api_test.7z

I will think about how to do with WM_GETTEXT.

EDIT : in this case we also need a XML API. I don't want to use msxml because it will add a dependancy (it is not staticaly linkable).

dimzon
26th February 2008, 17:41
sorry I don't know very well how to do with WM_GETTEXT and I began to do it yesterday with I will think about how to do with WM_GETTEXT.
Actually you doesn't need to do anything complex. Just create invisible window and update it's text everytime... :)

in this case we also need a XML API. I don't want to use msxml because it will add a dependancy (it is not staticaly linkable).
You doesn't need any XML API in this case - everything you need is simple string concatenation and special symbol replacement ;)

MatMaul
26th February 2008, 21:50
I added some new features, you can choose the subtitle and audio tracks now,get the playlist, the list of audio tracks and subtitle tracks.
it is available for testing on the same link.

Casimir666
26th February 2008, 22:32
1) How about to make MPC out-of-process COM server?
It's a little more complicated (need one interface for command and one for callback), and need to be register executable on machine to works. Maybe we will stay on the wm_copymessage solution for the moment ;)


2) How about to split MPC into 2 parts. First part - mplayerc.dll will contain everything playback-related. Second part mplayerc.exe will be frontend.
Could be interesting, but i have no idea how complicated it will be to transform mpc in dll...

jmnk
2nd March 2008, 00:30
sorry I don't know very well how to do with WM_GETTEXT and I began to do it yesterday with WM_COPYDATA.
here is my work :
http://www.etud.insa-toulouse.fr/~mvelten/bordel/mpc_api_test.7z

I will think about how to do with WM_GETTEXT.

EDIT : in this case we also need a XML API. I don't want to use msxml because it will add a dependancy (it is not staticaly linkable).
how do I use inclued sample app? when I try to run it I get 'cannot be executed' error. Do I miss some microsoft libraries? Any help woul dbe greatly appreciated.

linx05
7th March 2008, 15:33
@Casimir666
When will we see this API added to the latest releases of MPC HC? I am very interested (http://forum.doom9.org/showthread.php?t=126582) in seeing MPC have an API.

MatMaul
7th March 2008, 22:50
commited in the svn repository.
here is a build :
http://www.etud.insa-toulouse.fr/~mvelten/bordel/mplayerc_r443.7z

Some features are still missing.

Casimir666
7th March 2008, 23:12
how do I use inclued sample app? when I try to run it I get 'cannot be executed' error. Do I miss some microsoft libraries? Any help woul dbe greatly appreciated.

API sample application is also available in SF :
http://mpc-hc.svn.sourceforge.net/viewvc/mpc-hc/trunk/src/apps/MPCTestAPI/

tatoosh11
5th September 2009, 09:46
hi there.

i love the mpc-hc but the OSD sucks ;)

i am a new c# developer and want to write some code - maybe get the osd infos by the webinterface from mpc-hc.

can u give me some tips or links where i can start at?

Mitchjs
6th March 2011, 06:29
when i do...

mpc-hc.exe /fullscreen /slave 5115852

it opens as slave, but not fullscreen... seems once i do "/slave hwnd" other commands are issue
is this correct as programmed? or bug?