Both “libvlc_media_player_set_xwindow” and “libvlc_media_player_set_drawable” exhibit the same behavior.
I have a better grasp of the problem now. LibVLC crashes when you attempt to set the X Window ID handle to a non-existent handle, and I was trying to find out what that value is, but it doesn’t appear that my Juce implementation has a X Window ID value for my content component. In fact I’m starting to think that it isn’t possible for a content component to have a unique X Window ID handle. Thus the juce application crashes when you try to set the window to anything other than a known value (DocumentWindow’s value), like so:
[attachment=2]ss1.png[/attachment]
While the media player runs, I used the “xwininfo” tool to find the value of the X Window ID, and the only value that can be found is that of the juce DocumentWindow - there doesn’t appear to be a X Window ID value for the content component.
Is it possible that a content component can have a unique X Window ID handle value that is different from the DocumentWindow that it was set to? If so, how do I implement my code and find the handle? Because I was looking at Component::getNativeHandle:
void* Component::getWindowHandle() const throw()
{
const ComponentPeer* const peer = getPeer();
if (peer != 0)
return peer->getNativeHandle();
return 0;
}
I see that this member uses getPeer() to return the heavyweight window used by the content component. I wasn’t sure if adding the component to the desktop with Component::addToDesktop made a difference in being able to produce a unique X Window ID handle for the content component.
What I am trying to achieve in my Juce application: I’d like to hook the LibVLC player into the smaller content component’s dimensions (1134 x 562), rather than the larger DocumentWindow’s dimensions (1136 x 590). Why do I want to do this? Because it will be hard to control and use the media player if the media player output uses the exact dimensions of the parent DocumentWindow (1136 x 590). I’ll try to depict why here. First, here is a screen shot of the application before the user has pushed the “Play” textButton.
[attachment=1]ss2.png[/attachment]
Then when the user selects the “Play” textButton, this is what they see:
[attachment=0]ss3.png[/attachment]
As you can see, the LibVLC media player has filled the exact dimensions (1136 x 590) of the DocumentWindow. As a result, the user can no longer see the title bar or the maximise/minimise/close buttons on the DocumentWindow. This makes the application less user friendly. That’s why I would like to hook the LibVLC media player into a smaller dimension window, such as the size of the content component (1134 x 562). Then I could add the control buttons (play, stop, pause) to the top of the component. For a good and simple design, I wanted to keep the video output and video control within the same component. If I can’t set the video output to a smaller X Window ID, then I’ll have to have two components. One for video output, and the other for video control - and I’ll have to share libvlc variables between the components.
So in the hopes that I am just too close to this problem to think outside the box, is there any way to creatively solve this problem, setting the VLC output to a smaller resolution X Window ID that doesn’t fill the entire DocumentWindow?
Here is my VideoComponent constructor:
VideoComponent::VideoComponent()
: textButtonPlay (0),
textButtonPause (0),
textButtonStop (0)
{
addAndMakeVisible (textButtonPlay = new TextButton (T("new button")));
textButtonPlay->setButtonText (T("Play"));
textButtonPlay->addButtonListener (this);
addAndMakeVisible (textButtonPause = new TextButton (T("new button")));
textButtonPause->setButtonText (T("Pause"));
textButtonPause->addButtonListener (this);
addAndMakeVisible (textButtonStop = new TextButton (T("new button")));
textButtonStop->setButtonText (T("Stop"));
textButtonStop->addButtonListener (this);
addToDesktop(ComponentPeer::windowIsResizable,0);
int windowID;
windowID = (int) getWindowHandle();
printf("In Constructor, Window ID: %d\n",windowID);
//Set Bounds
setBoundsRelative(0.0547f, 0.0931f, 0.8860f, 0.7022f);
}
and here is the listener for Play:
void VideoComponent::buttonClicked (Button* buttonThatWasClicked)
{
if (buttonThatWasClicked == textButtonPlay)
{
char width[32], height[32];
sprintf(width, "%i", VIDEOWIDTH);
sprintf(height, "%i", VIDEOHEIGHT);
const char * const vlc_args[] =
{
"-I", "dummy",
"--vmem-width", width,
"--vmem-height", height,
"--ignore-config"
};
libvlc_exception_t ex;
libvlc_instance_t * inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;
libvlc_exception_init (&ex);
inst = libvlc_new (sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &ex);
raise (&ex);
m = libvlc_media_new (inst, "sample-video.mov", &ex);
raise (&ex);
mp = libvlc_media_player_new_from_media (m, &ex);
raise (&ex);
int pwidth = getParentWidth();
int pheight = getParentHeight();
printf("parent dimensions: %d x %d\n",pwidth,pheight);
int cwidth = getWidth();
int cheight = getHeight();
printf("component dimensions: %d x %d\n",cwidth,cheight);
int WinId = (int) getWindowHandle();
printf("After pushing Play button, Window ID: %d\n",WinId);
libvlc_media_player_set_xwindow(mp, (uint32_t) getWindowHandle(), &ex);
libvlc_media_release (m);
libvlc_media_player_play (mp, &ex);
raise (&ex);
//sleep(10);
//libvlc_media_player_stop (mp, &ex);
//libvlc_media_player_release (mp);
//libvlc_release (inst);
//raise (&ex);
}