I have written a simple Swing-based JVLC client with the latest 0.9.0-test3 jar library (http://jvlc.ihack.it/releases/jvlc-core ... 080727.jar) and I have experienced some problems with the Swing integration.
My sample application just adds video file to a canvas and playing with the class MediaListPlayer. But the applications fails when the second video start to play and I take this error.
Code: Select all
[????????] x11 video output error: X11 request 20.0 failed with error code 3:
BadWindow (invalid Window parameter)
X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 20 (X_GetProperty)
Resource id in failed request: 0x2c000d1
Serial number of failed request: 5131
Current serial number in output stream: 5131
Code: Select all
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* MainGUI.java
*
* Created on 26/01/2009, 09:06:26
*/
package com.alexander.GUI;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.videolan.jvlc.VLCException;
/**
*
* @author Administrador
*/
public class MainGUI extends javax.swing.JFrame {
private SmallVideoPanel actualSmallVideo = null;
/** Creates new form MainGUI */
public MainGUI() {
initComponents();
}
void reparentVideo(MouseEvent e){
try {
SmallVideoPanel smallVideo = (SmallVideoPanel) e.getComponent();
System.out.println("End?" + smallVideo.isEndOfVideo());
if (smallVideo.isEndOfVideo()) {
JOptionPane.showMessageDialog(null, "Esse video ja foi encerrado!");
jPanelRightBar.remove(smallVideo);
actualSmallVideo = null;
this.validate();
return;
}
if (actualSmallVideo != null) {
if (actualSmallVideo != smallVideo) {
actualSmallVideo.reparentBack();
}
}
this.actualSmallVideo = smallVideo;
smallVideo.reparent(canvas1);
configureMainPanel();
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
private void configureMainPanel() {
try {
jCheckBoxIsMute.setSelected(actualSmallVideo.isMute());
jLabelNome.setText(actualSmallVideo.getPath());
Dimension dimension = actualSmallVideo.getDimension();
jLabelResolution.setText(dimension.getWidth() + " X " + dimension.getHeight());
if (actualSmallVideo.isRunning()) {
jButtonStartPause.setText("Pause");
} else {
jButtonStartPause.setText("Play");
}
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
menu2 = new java.awt.Menu();
jScrollPane1 = new javax.swing.JScrollPane();
jPanelRightBar = new javax.swing.JPanel();
canvas1 = new java.awt.Canvas();
jButtonStartPause = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabelNome = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jCheckBoxIsMute = new javax.swing.JCheckBox();
jLabel7 = new javax.swing.JLabel();
jLabelResolution = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
menu1.setLabel("File");
menuBar1.add(menu1);
menu2.setLabel("Edit");
menuBar1.add(menu2);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jPanelRightBar.setLayout(new javax.swing.BoxLayout(jPanelRightBar, javax.swing.BoxLayout.PAGE_AXIS));
jScrollPane1.setViewportView(jPanelRightBar);
canvas1.setBackground(new java.awt.Color(102, 102, 102));
jButtonStartPause.setText("Pause");
jButtonStartPause.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonStartPauseActionPerformed(evt);
}
});
jButton2.setText("Visualizar Conexões");
jLabel1.setText("Nome:");
jLabel2.setText("Local:");
jLabelNome.setText("Video X");
jLabel4.setText("POP - PB");
jLabel5.setText("Projetor:");
jLabel6.setText("XX");
jButton3.setText("/\\");
jButton4.setText("<");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton5.setText(">");
jButton6.setText("\\/");
jCheckBoxIsMute.setText("Mute");
jCheckBoxIsMute.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBoxIsMuteActionPerformed(evt);
}
});
jLabel7.setText("Resolução:");
jLabelResolution.setText("800 X 800");
jMenu1.setText("File");
jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
jMenuItem1.setText("Abrir");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButtonStartPause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelNome)
.addComponent(jLabel4))
.addGap(90, 90, 90)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabelResolution)))
.addComponent(canvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 587, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(65, 65, 65)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton3)
.addComponent(jButton6)))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jCheckBoxIsMute)
.addComponent(jButton4))))
.addGap(6, 6, 6)
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabelNome)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jLabel4)
.addComponent(jLabel7)
.addComponent(jLabelResolution))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jCheckBoxIsMute)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 288, Short.MAX_VALUE)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton5)
.addComponent(jButton4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton6))
.addComponent(canvas1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonStartPause)
.addComponent(jButton2))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFileChooser chooser = new JFileChooser(".");
chooser.showOpenDialog(null);
String path = chooser.getSelectedFile().getAbsolutePath();
SmallVideoPanel smallVideo = new SmallVideoPanel(path);
smallVideo.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
reparentVideo(e);
}
});
jPanelRightBar.add(smallVideo);
jScrollPane1.validate();
smallVideo.initAndPlay();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jCheckBoxIsMuteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(actualSmallVideo != null){
while(actualSmallVideo.isMute() != jCheckBoxIsMute.isSelected()){
actualSmallVideo.setMute(jCheckBoxIsMute.isSelected());
System.out.println("Mute: " + actualSmallVideo.isMute() + " " + jCheckBoxIsMute.isSelected());
}
}
}
private void jButtonStartPauseActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
actualSmallVideo.togglePause();
if(jButtonStartPause.getText().equals("Play")){
jButtonStartPause.setText("Pause");
}
else{
jButtonStartPause.setText("Play");
}
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private java.awt.Canvas canvas1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButtonStartPause;
private javax.swing.JCheckBox jCheckBoxIsMute;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabelNome;
private javax.swing.JLabel jLabelResolution;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JPanel jPanelRightBar;
private javax.swing.JScrollPane jScrollPane1;
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.MenuBar menuBar1;
// End of variables declaration
}
Code: Select all
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SmallVideoPanel.java
*
* Created on 26/01/2009, 09:08:14
*/
package com.alexander.GUI;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import org.videolan.jvlc.Audio;
import org.videolan.jvlc.JVLC;
import org.videolan.jvlc.Playlist;
import org.videolan.jvlc.VLCException;
import org.videolan.jvlc.Video;
/**
*
* @author Administrador
*/
public class SmallVideoPanel extends javax.swing.JPanel {
private static ImageIcon image = new ImageIcon("teste.jpg");
private String path;
private JVLC jvlc;
private Playlist playList;
private Audio audio;
private Video video;
private boolean isPause = false;
/** Creates new form SmallVideoPanel */
public SmallVideoPanel() {
initComponents();
}
public SmallVideoPanel(String path) {
String [] args = {};//{/*"udp://@192.168.0.100:1234",*/"--plugin-path=C:\\Users\\Administrador\\Documents\\Downloads\\vlc-0.9.8a-win32\\vlc-0.9.8a\\plugins"};
initComponents();
this.path = path;
this.jvlc = new JVLC(args);
this.audio = new Audio(jvlc);
audio.setVolume(0);
this.video = new Video(jvlc);
}
public Dimension getDimension() {
return this.video.getSize(this.playList.getMediaInstance());
}
public String getPath() {
return this.path;
}
void initAndPlay() {
try {
jvlc.setVideoOutput(canvas1);
/* MediaDescriptor descriptor = new MediaDescriptor(jvlc, path);
MediaList list = new MediaList(jvlc);
this.mediaListPlayer = new MediaListPlayer(jvlc);
this.mediaListPlayer.setMediaList(list);
this.mediaListPlayer.play();*/
this.playList = new Playlist(jvlc);
playList.add(path, path);
playList.play();
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
boolean isMute() {
if(audio.getVolume() == 0) return true;
else return false;
//return audio.getMute();
}
boolean isRunning() throws VLCException {
this.isPause = !this.isPause;
return this.playList.isRunning();
}
boolean isEndOfVideo() throws VLCException{
if(!this.isPause && !this.playList.isRunning()){
return true;
}
else {
return false;
}
}
void togglePause() throws VLCException {
this.playList.togglePause();
}
void play(String path) {
try {
playList.add(path, path);
playList.next();
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
void removeAllVideos() {
try {
playList.stop();
playList.deleteItem(0);
} catch (VLCException ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
void reparent(Canvas canvas) {
jvlc.setVideoOutput(canvas);
audio.setVolume(100);
this.canvas1.setVisible(false);
this.jLabel1.setIcon(image);
this.jLabel1.setText("");
}
void reparentBack() {
audio.setVolume(0);
jvlc.setVideoOutput(this.canvas1);
this.canvas1.setVisible(true);
this.jLabel1.setIcon(null);
this.jLabel1.setText("Texto Normal");
}
public void setMute(boolean selected) {
if(selected){
audio.setVolume(0);
}
else{
audio.setVolume(100);
}
//this.audio.setMute(selected);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
canvas1 = new java.awt.Canvas(){
private boolean showImage = false;
private Image image = new ImageIcon("C:\\Users\\Administrador\\Documents\\NetBeansProjects\\GTMDA\\teste.jpg").getImage();
public void paint(Graphics g) {
System.out.println("Teste123");
if(showImage){
g.drawImage(image, 0, 0, canvas1);
}
else{
g.clearRect(0, 0, canvas1.getWidth(), canvas1.getHeight());
}
}
public void setShowImage(boolean showImage){
this.showImage = showImage;
repaint();
}
}
;
jLabel1 = new javax.swing.JLabel();
setMaximumSize(new java.awt.Dimension(147, 162));
setMinimumSize(new java.awt.Dimension(147, 162));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("jLabel1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(canvas1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(canvas1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>
// Variables declaration - do not modify
private java.awt.Canvas canvas1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
More information:
OS : Debian Lenny 2.6.26-1-686 #1 SMP Mon Dec 15 18:15:07 UTC 2008 i686 GNU/Linux
VLC version: vlc-0.9.8a
Compiling with options: ./configure --enable-debug --enable-dv --enable-dvdread --enable-v4l --enable-pvr --enable-faad --enable-twolame --enable-flac --enable-snapshot --enable-caca --enable-galaktos --enable-lirc --enable-mozilla --with-live555-tree=/usr/lib/live
(and cp /home/alexander/Desktop/vlcCompilado/lib/*. /usr/lib)
Hope somebody can help me with these issues. Your help is much appreciated.