cancel
Showing results for 
Search instead for 
Did you mean: 

PB control mplayer via Named Pipes

Former Member
0 Kudos

I'm trying to write a program that will control a few instances of mplayer (video player). Mplayer allows other apps to control it through named pipes and I'm having battles trying to get it to work. I'm hoping someone here has done this before and can supply an example for me. For others, here is a line command that starts mplayer:-

"C:\Program Files (x86)\mplayer\mplayer.exe" -vo gl -noborder -xineramascreen -2 -x 1920 -y 1080 -quiet "C:\Tomorrowland Trailer 3.wmv"

To run it in slave mode where a pipe can be used, you would add another parameter "-slave" after the "-quiet" that opens a command prompt which you can then type mplayer line commands (such as play or stop, etc.) and the player will action. You can also add "-input file=xxx" after -slave which makes it a work with a named pipe.

Either way, I need help running mplayer through PB. Anyone?

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi guys, Thanks for your input. I am in Sydney, Australia,  so it was great to wake up this morning to so many replies...

I have investigated using the CreateNamedPipe followed by CreateFile. The CreateNamedPipe function is quit involved with structures pointing to other structures where I could not find any info on how to define that second structure. This is what it says:-

"Because the internal format of a security descriptor can vary, we recommend that applications not modify theSECURITY_DESCRIPTOR structure directly"   ugh!

If anyone has an example app, I would love to use that code - a shortcut I know but I'm stumped on this one.

Former Member
0 Kudos

I'm pretty sure the player program will be the one that creates the named pipe. Your PB app only has to open it, write to it, and close it. That can be done with the standard file functions.

Former Member
0 Kudos

I just checked the source of one of the control apps for windows (it's in Delphi) and it's creating the named pipe itself, so what David is saying about it needing to exist prior to mplayer being called is partially correct.

I've looked at a couple of sample apps that control mplayer (one in Delphi, another in MSVC++), doing it from within PB is going to be a lot of work. There is no -input flag used, instead, the STDIN/STDOUT handles are supplied to the mplayer program using the STARTUPINFO structure of the Windows API CreateProcess function. The createpipe function is used to duplicate and create the new handles that are sent.

Look for mplayer gui on the projects page at mplayer (here: MPlayer - The Movie Player). This project is 4 years old, but it's CPP files have what you're looking for (I think).

What functions are you looking to use from mplayer? Might it be possible to find an ActiveX object, or similar to handle it?

Former Member
0 Kudos

The STARTUPINFO structure can be found in my RunAndWait example.

http://www.topwizprogramming.com/freecode_runandwait.html

Former Member
0 Kudos

mkfifo is only needed on linux. In Winodws, mplayer itself has to use CreateNamedPipe to initialize the pipe and listen for commands.

There are samples for named pipe client apps at the MSDN site. Here's a link to one of them that should give an idea of what's needed. Named Pipe Client (Windows)

Roland is right about opening the pipe. PB itself may not call CreateFile when using FileOpen, but it can't hurt to try. Failing that, you'll need to define the Windows API calls as external functions and call them directly.

In Windows, named pipes look like this "\\.\pipe\SomePipeName".

Former Member
0 Kudos

The PowerBuilder function FileOpen uses the CreateFile function so it should work if you use the correct name.

Former Member
0 Kudos

Actually, it's the other way around. MPlayer expects the pipe to exist otherwise it just closes straight away when you specify a pipe in the line command.

Former Member
0 Kudos

Based on what I saw (http://www.mplayerhq.hu/DOCS/tech/slave.txt), I think you're missing something.  It appears you need to create a pipe and pass the pipe name using "-input file".  The reference to mkfifo is (should be?) creating a pipe, though the example doesn't make much sense without anything obvious writing to the pipe.  Then again, I don't know exactly what mkfifo does beyond creating the pipe.

Former Member
0 Kudos

I think what needs to be done is run mkfifo to create a named pipe and then in the PowerBuilder app open the pipe, write commands to it and then close. A named pipe is handled with the same Win API functions as regular text file on disk. The difference is that it is actually in memory and when the player app reads a line, it disappears from the pipe. It is a FIFO stack basically.

I don't know if the PB built in functions can handle pipes, the Win API functions may be needed.

My FTP example has definitions of all the relevant API functions.

Topwiz Software - FTPClient

Former Member
0 Kudos

You can access pipes with the CreateFile Windows API function. CreateFile is the equivalent of the PB function FileOpen except it is more flexible. The equivalent of FileClose is CloseHandle. I have not used it with pipes myself but it should work.

CreateFile function (Windows)

Former Member
0 Kudos

Hi David;

  I have not used this 3rd party player but I have written PB code using the MCI (Multimedia Command Interface) to control video and audio features in MS-Windows. If mPLayer can interface that way - you could use that approach. FYI: MCI

Regards .. Chris