I am currently in the position of having 2 pieces of work I wish to combine. I have a simple media player running in a JFrame and a GUI I would like to add video playback to on a JPanel.
The code for the which creates video player window is as follows:
private final JFrame vidFrame;
private final EmbeddedMediaPlayerComponent vidComp;
//Creates JPanel for video player
public Video() {
vidFrame = new JFrame("VLC video test");
vidFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
vidFrame.setLocation(100, 100);
vidFrame.setSize(800, 800);
vidComp = new EmbeddedMediaPlayerComponent();
//This is the point where I am trying to add the video player to the GUI
MainWindow.vidPanel.add(vidComp);
vidFrame.add(vidComp);
vidFrame.setVisible(true);
}
And this is the panel I'm trying to add the player to:
JPanel vidPanel = new JPanel();
vidPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
vidPanel.setBounds(10, 11, 532, 400);
contentPane.add(vidPanel);
I get the error message: "vidPanel cannot be resolved or is not a field"
Does anyone know how I can rectify this?
Firstly, it looks like your vidPanel
is a local variable and should be a field if you need to access it from other methods. This is a pretty basic piece of Java - any beginners tutorial should cover this. VLCJ isn't the simplest thing to use and you may come unstuck if you're not clear on the fundamentals.
Secondly, before you head too far down that track, an embedded VLCJ player doesn't work with a JPanel, just a native AWT Canvas - so you'll need to use that instead.