EmbeddedMediaPlayerComponent not working with GridBagLayOut

This forum is about all development around libVLC.
aneeshsebastian
Blank Cone
Blank Cone
Posts: 18
Joined: 16 May 2011 08:03

EmbeddedMediaPlayerComponent not working with GridBagLayOut

Postby aneeshsebastian » 13 Apr 2013 09:39

I develop a swing application which has multiple UI component. It has a video display panel and video control panel. I embed EmbeddedMediaPlayerComponent to my custom video display panel. My EmbeddedMediaPlayerComponent instance is added with another custom panel called videocontrol panel which controls the video. I use grid bag layout as multiple panel components are involved.
EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
mediaPlayerComponent.setLayout(new GridBagLayout());

I had to do this as GridBagLayout is the expected layout manager. When I set this, video is not getting displayed, but just a blank black window appears. If I change the layout to BorderLayout it works without issue. Would not EmbeddedMediaPlayerComponent support layouts other than BorderLayout. Pls share with me if u have any working examples

sherington
Cone that earned his stripes
Cone that earned his stripes
Posts: 491
Joined: 10 Sep 2008 11:57
VLC version: master
Operating System: Linux

Re: EmbeddedMediaPlayerComponent not working with GridBagLay

Postby sherington » 13 Apr 2013 12:09

Would not EmbeddedMediaPlayerComponent support layouts other than BorderLayout.
Of course it would. Your constraints are probably wrong, but since you didn't post your code, it's impossible to say.

GridBag sucks. I always prefer nested BorderLayout, with BoxLayout as needed.

Anyway here's your two-minute example.

Code: Select all

import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent; public class GridBagTest { private final JFrame f; private final EmbeddedMediaPlayerComponent mediaPlayer; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new GridBagTest().start(); } }); } private GridBagTest() { GridBagLayout gbl = new GridBagLayout(); JPanel cp = new JPanel(); cp.setLayout(gbl); GridBagConstraints gbc; gbc = new GridBagConstraints(); gbc.weightx = 1.0f; gbc.weighty = 1.0f; gbc.fill = GridBagConstraints.BOTH; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.CENTER; mediaPlayer = new EmbeddedMediaPlayerComponent(); cp.add(mediaPlayer, gbc); gbc = new GridBagConstraints(); gbc.weightx = 1.0f; gbc.weighty = 0.0f; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.CENTER; JPanel someOtherPanel = new JPanel(); someOtherPanel.add(new JButton("Play")); someOtherPanel.add(new JButton("Stop")); someOtherPanel.add(new JButton("Pause")); cp.add(someOtherPanel, gbc); f = new JFrame("Test"); f.setContentPane(cp); f.setSize(800, 600); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } private void start() { mediaPlayer.getMediaPlayer().playMedia("your-movie.mpg"); } }

aneeshsebastian
Blank Cone
Blank Cone
Posts: 18
Joined: 16 May 2011 08:03

Re: EmbeddedMediaPlayerComponent not working with GridBagLay

Postby aneeshsebastian » 13 Apr 2013 12:41

Thanks for the reply.

I have a couple of question on EmbeddedMediaPlayerComponent implementation

1. EmbeddedMediaPlayerComponent seems extending Panel instead of JPanel.
2. The video surface is always an AWT Canvas. Can't we make it as JPanel? AWT Canvas is heavy weight. I cannot change the default behavior as native libraries implementation is tightly coupled,right?


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 18 guests