Board index » kylix » hosting mplayer

hosting mplayer


2006-03-07 08:21:48 AM
kylix1
I've been trying to embed an mplayer video into a Kylix app.
This should be possible because you can give the mplayer a "wid"
argument passing the WinID of the hosting window.
I've tried to do this for a TForm. For getting the WinID I used this
function for Form1.Canvas.Handle:
function XIDFromPainter(Painter: QPainterH): XID;
var device: QPaintDeviceH;
begin
device := QPainter_device(Painter);
if device <>nil then
Result := XID(QPaintDevice_handle(device))
else
Result := 0;
end;
Calling Mplayer like this:
Cmd:='/usr/bin/mplayer -slave -nojoystick -wid '+inttostr(WinID)+'
/home/theo/vd/myvideo.mpg &';
Libc.System(Pchar(Cmd));
Mplayer actually seems happy, plays the video (as console output is
showing progress) and you can hear the sound.
(Note that mplayer aborts with an invalid WinID).
But there's no video visible on the Form.
Then I made a test with a plain X11 Window. The video is shown on the
main Window (the one with decorations) as well as on a ChildWin.
Everything fine, reacts even on Keyboard events.
Then, I've tried to host an X11 Window on a Kylix-Form somewhat like
this (OnShow event):
...
dpy:=Application.Display;
Canvas.Start;
mainWin:=XidFromPainter(Canvas.Handle);
childWin := XCreateSimpleWindow(dpy,
mainWin,
XDefaultRootWindow(dpy),
25, 25,
300, 300,
0,
blackColor, blackColor);
XMapWindow(dpy, childWin);
XFlush(dpy);
Canvas.Stop;
...
This shows a persistent black rectangle on my Form1, meaning the XWindow
is there and moving happily with the Form1.
Mplayer again is happy with its handle, but same result: no video visible.
If I only change one parameter in this, instead of passing mainWin, I
pass XDefaultRootWindow(dpy) to XCreateSimpleWindow,
I can see the video, although in a separate window.
Note again, that it's not a problem of the window not beeing a direct
child of the root-window (Screen), as it works well in plain X.
What's wrong here? Can I cure this with some widgetflags or bypassing
some X11Events or is this just impossible in Kylix/Qt and why?
 
 

Re:hosting mplayer

theo wrote:
Quote
I've been trying to embed an mplayer video into a Kylix app.

This should be possible because you can give the mplayer a "wid"
argument passing the WinID of the hosting window.

I've tried to do this for a TForm. For getting the WinID I used this
function for Form1.Canvas.Handle:
I am not sure if this will help you or not as I haven't tried it. However,
you might try passing the result of calling QWidget_winId(Form1.Handle) and
see what happens.
HTH
Gordon Hicks
 

Re:hosting mplayer

Gordon Hicks schrieb:
Quote

I am not sure if this will help you or not as I haven't tried it. However,
you might try passing the result of calling QWidget_winId(Form1.Handle) and
see what happens.

Thanks Gordon for your attention.
While it's true that this really gives a different result (WinID):
for example:
writeln(QWidget_winId(Handle)); -->71303199
writeln(XIDFromPainter(Canvas.Handle)); -->71303202
It doesn't really help for showing the video.
Who could shed some light on this? Andreas Hausladen? :-)
 

{smallsort}

Re:hosting mplayer

If someone is interested in how I've tested the "plain X" code, here is
the minimalistic version. It's showing the video in a child-window in my
case for 20 secs.
program Project1;
uses
Xlib, SysUtils,
Libc, LibcExec;
{$APPTYPE CONSOLE}
var
dpy: PDisplay;
blackColor: Cardinal;
mainWin, childWin: TWindow;
event: PXEvent;
Str:STring;
begin
dpy := XOpenDisplay(NIL);
blackColor := XBlackPixel(dpy, XDefaultScreen(dpy));
mainWin := XCreateSimpleWindow(dpy,
XDefaultRootWindow(dpy),
0, 0,
200, 200,
0,
blackColor, blackColor);
childWin := XCreateSimpleWindow(dpy,
mainWin,
25, 25,
150, 150,
0,
blackColor, blackColor);
XSelectInput(dpy, mainWin, StructureNotifyMask);
XMapWindow(dpy, mainWin);
XMapWindow(dpy, childWin);
new(event);
while true do
begin
XNextEvent(dpy, event);
if event^.xtype = MapNotify then
break;
end;
dispose(event);
XFlush(dpy);
Str:='/usr/bin/mplayer -slave -nojoystick -wid '+inttostr(childWin)+'
/home/theo/myvideo.mpg &';
Libc.System(Pchar(Str));
__sleep(20); //Show for 20 secs.
end.
 

Re:hosting mplayer

theo wrote:
Quote
I've been trying to embed an mplayer video into a Kylix app.

This should be possible because you can give the mplayer a "wid"
argument passing the WinID of the hosting window.

I've tried to do this for a TForm. For getting the WinID I used this
function for Form1.Canvas.Handle:

I didn't get it to work with qt2clx without using directly Xlib, but with
qt3clx you can do that. :)
 

Re:hosting mplayer

zeljko schrieb:
Quote
>

I didn't get it to work with qt2clx without using directly Xlib, but with
qt3clx you can do that. :)
Thanks Zeljko
What do you mean with "without using directly Xlib"?
Is this in a separate window or as a child of TForm?
Can you explain why it works for qt3clx but not for qt2clx?
 

Re:hosting mplayer

theo wrote:
Quote
zeljko schrieb:

>>
>
>I didn't get it to work with qt2clx without using directly Xlib, but with
>qt3clx you can do that. :)

Thanks Zeljko

What do you mean with "without using directly Xlib"?
Is this in a separate window or as a child of TForm?
No, you create an dummy XWindow, put mplayer window into,
and then reparent into your TForm.
so:
1.create new XWindow
2.Get it's winid (XID)
3.Start mplayer backend into XID window
4.Reparent XWindow into your form.
Quote
Can you explain why it works for qt3clx but not for qt2clx?
think that qt2 have some {*word*193} bugs...I didn't investigated this but it's
easy to check it.
Create an app with mainform ,and then execute eg. kdeshell clock with winid
parameter of your mainform.
With qt2 you get nothing, with qt3 you'll get clock settings embedded into
your form. :)
I've checked this few months ago, so sorry if there's some mistake in my
text :)
 

Re:hosting mplayer

zeljko schrieb:
Quote

No, you create an dummy XWindow, put mplayer window into,
and then reparent into your TForm.
so:
1.create new XWindow
2.Get it's winid (XID)
3.Start mplayer backend into XID window
4.Reparent XWindow into your form.


Thanks Zeljko!
You opened my eyes! It's working now.
But I have a bit a different conclusion:
You don't have to reparent the XWindow.
You can do it the way I took initally BUT:
After mplayer has taken over control of your window, the window is unmapped!
You have to go in a loop until you get a "MapRequest". Then
Map the window again and it works!
Thanks! Cheeers!
 

Re:hosting mplayer

theo wrote:
Quote
You opened my eyes! It's working now.
But I have a bit a different conclusion:

You don't have to reparent the XWindow.
You can do it the way I took initally BUT:

After mplayer has taken over control of your window, the window is
unmapped! You have to go in a loop until you get a "MapRequest". Then
Map the window again and it works!

Thanks! Cheeers!
yea, something like that, as I said it was few months ago ;)