jVLC 1.0.0git don't video output in a diferent canvas place
Posted: 17 Feb 2009 17:55
I try to do a application with VLC 1.0.0 git, i want put the video output of vlc in a canvas component in JPanel.
There are 2 ways to do this.
The first form is use the method reparent(MediaPlayer, Canvas) of class Video, but this method still not working, but there is a ticket to solve this problem.
The second form is use the method setVideoOutput(Canvas) of class JVLC, but this method not working too, that crash the JMV, there are same problem in the code of C in libxvideo_plugin.so. But i'm not sure!
I'm going to show my example code and please someone help me!
Excuse me for my English!
public class TesteJvlc {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.awt.GridBagConstraints gridBagConstraints;
JVLC jvlc;
Video video;
MediaPlayer mp;
MediaDescriptor ds;
Canvas jvcanvas;
JPanel jvcc;
jvlc = new JVLC(" --vvv");
ds = new MediaDescriptor(jvlc, "Elephants.avi");
mp = ds.getMediaPlayer();
video = new Video(jvlc);
//Canvas
GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphDevice = graphEnv.getDefaultScreenDevice();
GraphicsConfiguration graphicConf = graphDevice.getDefaultConfiguration();
jvcanvas = new java.awt.Canvas(graphicConf);
jvcanvas.setBackground(Color.black);
jvcanvas.setSize(800,600);
jvcanvas.invalidate();
jvcanvas.setVisible(true);
//Panel
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
jvcc = new JPanel(true);
jvcc.setLayout(new java.awt.GridBagLayout());
jvcc.setSize(jvcanvas.getWidth()+30, jvcanvas.getHeight()+50);
jvcc.add(jvcanvas, gridBagConstraints);
//Frame
JFrame frame = new JFrame("VLC");
frame.setBounds(0, 0,jvcc.getWidth(),jvcc.getHeight());
frame.setPreferredSize(new Dimension(jvcc.getWidth(), jvcc.getHeight()));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cner = frame.getContentPane();
cner.setLayout(new BoxLayout(cner, BoxLayout.Y_AXIS));
frame.setLayout(new FlowLayout());
frame.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
cner.add(jvcc, gridBagConstraints);
frame.pack();
frame.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent ev)
{
System.exit(0);
}
});
frame.setVisible(true);
jvcanvas.addNotify();
jvcanvas.requestFocus();
jvcanvas.createBufferStrategy(2);
//video.reparent(mp, jvcanvas); //first way
jvlc.setVideoOutput(jvcanvas); //second way
mp.play();
}
}
There are 2 ways to do this.
The first form is use the method reparent(MediaPlayer, Canvas) of class Video, but this method still not working, but there is a ticket to solve this problem.
The second form is use the method setVideoOutput(Canvas) of class JVLC, but this method not working too, that crash the JMV, there are same problem in the code of C in libxvideo_plugin.so. But i'm not sure!
I'm going to show my example code and please someone help me!
Excuse me for my English!
public class TesteJvlc {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.awt.GridBagConstraints gridBagConstraints;
JVLC jvlc;
Video video;
MediaPlayer mp;
MediaDescriptor ds;
Canvas jvcanvas;
JPanel jvcc;
jvlc = new JVLC(" --vvv");
ds = new MediaDescriptor(jvlc, "Elephants.avi");
mp = ds.getMediaPlayer();
video = new Video(jvlc);
//Canvas
GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphDevice = graphEnv.getDefaultScreenDevice();
GraphicsConfiguration graphicConf = graphDevice.getDefaultConfiguration();
jvcanvas = new java.awt.Canvas(graphicConf);
jvcanvas.setBackground(Color.black);
jvcanvas.setSize(800,600);
jvcanvas.invalidate();
jvcanvas.setVisible(true);
//Panel
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
jvcc = new JPanel(true);
jvcc.setLayout(new java.awt.GridBagLayout());
jvcc.setSize(jvcanvas.getWidth()+30, jvcanvas.getHeight()+50);
jvcc.add(jvcanvas, gridBagConstraints);
//Frame
JFrame frame = new JFrame("VLC");
frame.setBounds(0, 0,jvcc.getWidth(),jvcc.getHeight());
frame.setPreferredSize(new Dimension(jvcc.getWidth(), jvcc.getHeight()));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cner = frame.getContentPane();
cner.setLayout(new BoxLayout(cner, BoxLayout.Y_AXIS));
frame.setLayout(new FlowLayout());
frame.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.CENTER;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
cner.add(jvcc, gridBagConstraints);
frame.pack();
frame.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent ev)
{
System.exit(0);
}
});
frame.setVisible(true);
jvcanvas.addNotify();
jvcanvas.requestFocus();
jvcanvas.createBufferStrategy(2);
//video.reparent(mp, jvcanvas); //first way
jvlc.setVideoOutput(jvcanvas); //second way
mp.play();
}
}