SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Swing Video Player");
JLayeredPane layeredPane = new JLayeredPane();
frame.add(layeredPane, BorderLayout.CENTER);
final VideoPlayer full = new VideoPlayer(files[0]);
full.setPreferredSize(new Dimension(1024, 768));
full.setControlsVisible(true);
full.setBounds(0, 0, 640, 480);
full.getMediaPlayer().play();
layeredPane.add(full, JLayeredPane.DEFAULT_LAYER);
layeredPane.setPreferredSize(new Dimension(640, 480));
// Add a panel just above the main video
final JPanel pip = new JPanel();
pip.setOpaque(false);
pip.setBackground(new Color(0, 0, 0, 0));
layeredPane.add(pip, new Integer(1));
pip.setBounds(0, 0, 640, 480);
pip.setLayout(new FlowLayout());
// Add a button panel above that
final JPanel controls = new JPanel();
controls.setBounds(full.getBounds());
controls.setLayout(new BorderLayout());
layeredPane.add(controls, Integer.valueOf(2));
final JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BorderLayout());
JButton quit = new JButton("Quit");
buttonPanel.add(quit, BorderLayout.WEST);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
quit.setOpaque(false);
controls.add(buttonPanel, BorderLayout.NORTH);
controls.setOpaque(false);
buttonPanel.setOpaque(false);
layeredPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JComponent c = (JComponent) e.getComponent();
Rectangle r = c.getBounds();
full.setBounds(r);
pip.setBounds(r);
controls.setBounds(r);
c.revalidate();
}
});
for (int i = 1; i < files.length; ++i) {
String uri = files[i];
final VideoPlayer player = new VideoPlayer(uri);
player.setPreferredSize(new Dimension(200, 150));
player.setOpacity(0.4f);
player.setOpaque(false);
player.setControlsVisible(false);
Pipeline pipe = player.getMediaPlayer().getPipeline();
// Turn off sound - otherwise everything goes slow.
if (pipe instanceof PlayBin2) {
((PlayBin2) pipe).setAudioSink(ElementFactory.make("fakesink", "audio"));
}
pip.add(player);
// Stagger the start times, so gstreamer doesn't choke
javax.swing.Timer timer = new javax.swing.Timer(1000 * i, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
player.getMediaPlayer().play();
}
});
timer.setRepeats(false);
timer.start();
}