I am having a bit of trouble with nested JPanels playing a video. I have an AVPlayer class extend JPanel which plays up to 4 videos simultaneously. Each video is played inside its own canvas which is inside its own JPanel. All the panels are then put into the AVPlayer panel. But when I try to play the videos all I get is a black square.
I'm not sure what the actual problem in my bigger program is but I think I can solve it if I can get the videos to play using the second bit of code below. Can someone tell me why the first bit of code is properly able to display all the videos, but the second one is not.
Code that works:
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
AVPlayer player = new AVPlayer();
frame.getContentPane().add(player);
frame.revalidate();
String[] path = {"(ei)ga_00.mp4", "ei-utsu(ru)_00.mp4", "video.mp4"};
player.playVideo(path);
Code that shows one small black square
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
AVPlayer player = new AVPlayer();
JPanel panel = new JPanel();
panel.add(player);
frame.getContentPane().add(panel);
frame.revalidate();
String[] path = {"(ei)ga_00.mp4", "ei-utsu(ru)_00.mp4", "video.mp4"};
player.playVideo(path);
Change JPanel panel = new JPanel();
to JPanel panel = new JPanel(new BorderLayout());
Your AVPlayer
should also override the getPreferredSize
method of JPanel
and return the "preferred size" of the component, this way the layout managers have some hope of actually been able to do there jobs
See Laying Out Components Within a Container for more details
Beware that vlcj's primary video surface is a heavy weight component and mixing them on light weight containers can generate some undesirable effects