JVLC help
Posted: 10 Apr 2007 19:41
First I have a question. Are there anywhere installation instructions for JVLC under windows?
Second:
I try to open more than one jvlc instance. The problem is, that the player opens every player in a own window and when I open 5 or more players, jvlc generates me less than I expected. Have anyone a idea?
Second:
I try to open more than one jvlc instance. The problem is, that the player opens every player in a own window and when I open 5 or more players, jvlc generates me less than I expected. Have anyone a idea?
Code: Select all
package gui;
import javax.swing.JFrame;
public class JVLCMain{
public static void main (String[] args) {
JFrame.setDefaultLookAndFeelDecorated( true );
WorkingFrame wf = new WorkingFrame();
wf.setVisible(true);
}
}
Code: Select all
package gui;
import java.awt.GridBagConstraints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.plaf.InternalFrameUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.JVLCCanvas;
import org.videolan.jvlc.VLCException;
public class WorkingFrame extends JFrame{
private static final long serialVersionUID = 1587534065141936424L;
private JInternalFrame jif01_;
private JInternalFrame jif02_;
private JInternalFrame jif03_;
private JInternalFrame jif04_;
private JInternalFrame jif05_;
private JInternalFrame jif06_;
private JInternalFrame jif07_;
private JInternalFrame jif08_;
private JInternalFrame jif09_;
private JInternalFrame jif10_;
private JInternalFrame jif11_;
private JInternalFrame jif12_;
// public JVLCCanvas topPlayer_;
// public JVLCCanvas leftPlayer_;
// public JVLCCanvas rightPlayer_;
public JVLCCanvas bottomPlayer_;
// public JVLCCanvas middlePlayer_;
public JVLCCanvas webcamPlayer_;
public String topVideo_ = "file:///E:/SWP-Roboter/workspace/t-en.mpg";
public String leftVideo_ = "file:///E:/SWP-Roboter/workspace/l-bdb.mpg";
public String rightVideo_ = "file:///E:/SWP-Roboter/workspace/r-ehn.mpg";
public String bottomVideo_ = "file:///E:/SWP-Roboter/workspace/b-bdb.mpg";
public String stream_ = "udp://@224.0.0.1:4240";
private JMenuBar jmb_;
public WorkingFrame() {
this.addKeyListener(new ControlKeyListener(this));
this.jif01_ = new JInternalFrame();
this.jif02_ = new JInternalFrame();
this.jif03_ = new JInternalFrame();
this.jif04_ = new JInternalFrame();
this.jif05_ = new JInternalFrame();
this.jif06_ = new JInternalFrame();
this.jif07_ = new JInternalFrame();
this.jif08_ = new JInternalFrame();
this.jif09_ = new JInternalFrame();
this.jif10_ = new JInternalFrame();
this.jif11_ = new JInternalFrame();
this.jif12_ = new JInternalFrame();
// this.topPlayer_ = new JVLCCanvas();
// this.leftPlayer_ = new JVLCCanvas();
// this.middlePlayer_ = new JVLCCanvas();
// this.rightPlayer_ = new JVLCCanvas();
this.bottomPlayer_ = new JVLCCanvas();
this.webcamPlayer_= new JVLCCanvas();
this.jmb_ = new JMenuBar();
this.jmb_.add(new JMenu("Open"));
this.jmb_.add(new JMenu("File"));
this.jmb_.add(new JMenu("Login"));
this.setJMenuBar(this.jmb_);
this.initComponents();
this.addFrame();
}
public void initComponents() {
GridBagConstraints gridBagConstraints;
this.getContentPane().setLayout(new java.awt.GridBagLayout());
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
// first row
this.jif01_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui01 = this.jif01_.getUI();
((BasicInternalFrameUI)ui01).setNorthPane(null);
this.jif01_.setBorder(null);
getContentPane().add(this.jif01_, gridBagConstraints);
this.jif02_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui02 = this.jif02_.getUI();
((BasicInternalFrameUI)ui02).setNorthPane(null);
this.jif02_.setBorder(null);
getContentPane().add(this.jif02_, gridBagConstraints);
this.jif03_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui03 = this.jif03_.getUI();
((BasicInternalFrameUI)ui03).setNorthPane(null);
this.jif03_.setBorder(null);
getContentPane().add(this.jif03_, gridBagConstraints);
this.jif04_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui04 = this.jif04_.getUI();
((BasicInternalFrameUI)ui04).setNorthPane(null);
this.jif04_.setBorder(null);
getContentPane().add(this.jif04_, gridBagConstraints);
// second row
this.jif05_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui05 = this.jif05_.getUI();
((BasicInternalFrameUI)ui05).setNorthPane(null);
this.jif05_.setBorder(null);
getContentPane().add(this.jif05_, gridBagConstraints);
this.jif06_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 320;
gridBagConstraints.ipady = 240;
InternalFrameUI ui06 = this.jif06_.getUI();
((BasicInternalFrameUI)ui06).setNorthPane(null);
this.jif06_.setBorder(null);
getContentPane().add(this.jif06_, gridBagConstraints);
this.jif07_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui07 = this.jif07_.getUI();
((BasicInternalFrameUI)ui07).setNorthPane(null);
this.jif07_.setBorder(null);
getContentPane().add(this.jif07_, gridBagConstraints);
this.jif08_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui08 = this.jif08_.getUI();
((BasicInternalFrameUI)ui08).setNorthPane(null);
this.jif08_.setBorder(null);
getContentPane().add(this.jif08_, gridBagConstraints);
// third row
this.jif09_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui09 = this.jif09_.getUI();
((BasicInternalFrameUI)ui09).setNorthPane(null);
this.jif09_.setBorder(null);
getContentPane().add(this.jif09_, gridBagConstraints);
this.jif10_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui10 = this.jif10_.getUI();
((BasicInternalFrameUI)ui10).setNorthPane(null);
this.jif10_.setBorder(null);
getContentPane().add(this.jif10_, gridBagConstraints);
this.jif11_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui11 = this.jif11_.getUI();
((BasicInternalFrameUI)ui11).setNorthPane(null);
this.jif11_.setBorder(null);
getContentPane().add(this.jif11_, gridBagConstraints);
this.jif12_.setVisible(true);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.ipadx = 160;
gridBagConstraints.ipady = 120;
InternalFrameUI ui12 = this.jif12_.getUI();
((BasicInternalFrameUI)ui12).setNorthPane(null);
this.jif12_.setBorder(null);
getContentPane().add(this.jif12_, gridBagConstraints);
pack();
}
public void addFrame() {
// JVLCCanvas jvlcc01 = new JVLCCanvas();
// this.jif02_.add(jvlcc01);
// JVLC jvlc01 = jvlcc01.getJVLC();
// jvlc01.setMute(true);
// jvlc01.playlist.add(file2, "1");
// jvlc01.playlist.play(-1, null);
// this.jif02_.add(this.topPlayer_);
// JVLC jvlc01 = this.topPlayer_.getJVLC();
// jvlc01.playlist.add(this.stream_, "1");
// jvlc01.playlist.play(-1, null);
//
// this.jif05_.add(this.leftPlayer_);
// JVLC jvlc02 = this.leftPlayer_.getJVLC();
// jvlc02.playlist.add(this.stream_, "2");
// jvlc02.playlist.play(-1, null);
//
// this.jif06_.add(this.middlePlayer_);
// JVLC jvlc03 = this.middlePlayer_.getJVLC();
// jvlc03.playlist.add(this.stream_, "3");
// jvlc03.playlist.play(-1, null);
//
// this.jif07_.add(this.rightPlayer_);
// JVLC jvlc04 = this.rightPlayer_.getJVLC();
// jvlc04.playlist.add(this.stream_, "4");
// jvlc04.playlist.play(-1, null);
this.jif10_.add(this.bottomPlayer_);
JVLC jvlc05 = this.bottomPlayer_.getJVLC();
try {
jvlc05.playlist.add(this.topVideo_, "5");
jvlc05.playlist.play(-1, null);
} catch (VLCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.jif04_.add(this.webcamPlayer_);
JVLC jvlc06 = this.webcamPlayer_.getJVLC();
try {
jvlc06.playlist.add("dshow:// :dshow-vdev=\"Philips PCVC680 VGA-Kamera (Video, USB)\"", "6");
jvlc06.playlist.play(-1, null);
} catch (VLCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.jif04_.addMouseListener(new VideoControlMouseListener("WebcamPlayer",this));
this.webcamPlayer_.addMouseListener(new VideoControlMouseListener("WebcamPlayer",this));
this.jif02_.addMouseListener(new VideoControlMouseListener("TopPlayer",this));
Control cntrl = new Control(this);
cntrl.start();
cntrl.setVisible(true);
this.jif12_.add(cntrl);
}
/**
* KeyListener
* @author songoku
* TODO Implement Socket transmitting
*/
class ControlKeyListener implements KeyListener {
private WorkingFrame wf_;
public ControlKeyListener(WorkingFrame wf){
this.wf_ = wf;
}
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyPressed: " + e.getKeyCode());
if (e.getKeyCode() == 38) {
System.out.println("keyPressed: forward");
} else if (e.getKeyCode() == 37) {
System.out.println("keyPressed: left");
} else if (e.getKeyCode() == 39) {
System.out.println("keyPressed: right");
} else if (e.getKeyCode() == 40) {
System.out.println("keyPressed: back");
}
this.wf_.requestFocus();
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyReleased: " + e.getKeyCode());
if (e.getKeyCode() == 38) {
System.out.println("keyReleased: forward");
} else if (e.getKeyCode() == 37) {
System.out.println("keyReleased: left");
} else if (e.getKeyCode() == 39) {
System.out.println("keyReleased: right");
} else if (e.getKeyCode() == 40) {
System.out.println("keyReleased: back");
}
this.wf_.requestFocus();
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
System.out.println("keyTyped: " + e.getKeyCode());
this.wf_.requestFocus();
}
}
/**
* MouseListener
* @author songoku
* TODO Implementation not ready
*/
public class VideoControlMouseListener implements MouseListener {
private WorkingFrame wf_;
private String title_;
public VideoControlMouseListener(String title, WorkingFrame wf) {
this.title_ = title;
this.wf_ = wf;
}
public void mouseClicked(MouseEvent arg0) {
System.out.println("mouseClicked: " + this.title_);
this.wf_.requestFocus();
}
public void mouseEntered(MouseEvent arg0) {
System.out.println("mouseEntered: " + this.title_);
this.wf_.requestFocus();
}
public void mouseExited(MouseEvent arg0) {
System.out.println("mouseExited: " + this.title_);
this.wf_.requestFocus();
}
public void mousePressed(MouseEvent arg0) {
System.out.println("mousePressed: " + this.title_);
this.wf_.requestFocus();
}
public void mouseReleased(MouseEvent arg0) {
System.out.println("mouseReleased: " + this.title_);
this.wf_.requestFocus();
}
}
}
Code: Select all
package gui;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.plaf.InternalFrameUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import org.videolan.jvlc.VLCException;
public class Control extends JInternalFrame{
private static final long serialVersionUID = 9110558782732101855L;
public WorkingFrame wf_;
public Control (WorkingFrame wf) {
this.wf_ = wf;
InternalFrameUI ui = this.getUI();
((BasicInternalFrameUI)ui).setNorthPane(null);
this.setBorder(null);
}
public void start () {
GridBagConstraints gbc = null;
this.getContentPane().setLayout(new GridBagLayout());
JButton forward = new JButton("^");
forward.addActionListener(new ControlActionListener(this.wf_, "forward"));
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
this.getContentPane().add(forward,gbc);
JButton left = new JButton("<");
left.addActionListener(new ControlActionListener(this.wf_, "left"));
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
this.getContentPane().add(left,gbc);
JButton right = new JButton(">");
right.addActionListener(new ControlActionListener(this.wf_, "right"));
gbc = new GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 1;
this.getContentPane().add(right,gbc);
JButton back = new JButton("v");
back.addActionListener(new ControlActionListener(this.wf_, "back"));
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
this.getContentPane().add(back,gbc);
}
private class ControlActionListener implements ActionListener {
private WorkingFrame wf_;
private String direction_;
public ControlActionListener (WorkingFrame wf, String direction) {
this.wf_ = wf;
this.direction_ = direction;
}
public void actionPerformed(ActionEvent arg0) {
System.out.println(this.direction_);
if (this.direction_.compareTo("forward") == 0) {
try {
this.wf_.webcamPlayer_.getJVLC().playlist.stop();
this.wf_.webcamPlayer_.getJVLC().playlist.add(this.wf_.stream_, "1");
this.wf_.webcamPlayer_.getJVLC().playlist.play(-1,null);
this.wf_.requestFocus();
} catch (VLCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else if (this.direction_.compareTo("left") == 0) {
this.wf_.requestFocus();
}else if (this.direction_.compareTo("right") == 0) {
this.wf_.requestFocus();
}else if (this.direction_.compareTo("back") == 0) {
this.wf_.requestFocus();
}
}
}
}