Hola, pues el caso esque estoy "intentando" hacer una aplicación en la que puedas compartir video, en plan curiosidad.
Ya he conseguido acceder a la cam del pc (JMF), para ello he creado una clase (panelVideo) que hereda de jPanel y que cuando uso el método comenzar() me muestra el contenido de la cam en el mismo panel.
El problema lo tengo ahora, cuando intento enviar mi clase panelVideo por socket mediante ObjectInputStream/ObjectOutputStream, me tira la siguiente excepción:
09-jun-2010 12:17:50 clientehora.GUIClienteHora getTime
GRAVE: null
java.lang.ClassNotFoundException: panelVideo
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at clientehora.GUIClienteHora.getTime(GUIClienteHora.java:105)
at clientehora.GUIClienteHora.access$000(GUIClienteHora.java:22)
at clientehora.GUIClienteHora$1.actionPerformed(GUIClienteHora.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1041)
at java.awt.Container.add(Container.java:365)
at clientehora.GUIClienteHora.getTime(GUIClienteHora.java:112)
at clientehora.GUIClienteHora.access$000(GUIClienteHora.java:22)
at clientehora.GUIClienteHora$1.actionPerformed(GUIClienteHora.java:52)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
public class GUIClienteVideo extends javax.swing.JFrame {
String direccionIp = "localhost";
String puerto = "7000";
public GUIClienteVideo() {
initComponents();
etiquetaHora.setHorizontalAlignment(JLabel.CENTER);
textoHora.setEnabled(false);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
panelBotones = new javax.swing.JPanel();
botonActualizarHora = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
panelHora = new javax.swing.JPanel();
etiquetaHora = new javax.swing.JLabel();
panelHoraTexto = new javax.swing.JPanel();
textoHora = new javax.swing.JTextField();
panelVisorVideo = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Time client");
botonActualizarHora.setText("update time");
botonActualizarHora.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
getVideo(evt);
}
});
panelBotones.add(botonActualizarHora);
jButton1.setText("set/change server");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
setIP(evt);
}
});
panelBotones.add(jButton1);
getContentPane().add(panelBotones, java.awt.BorderLayout.SOUTH);
panelHora.setLayout(new java.awt.GridLayout(2, 1));
etiquetaHora.setFont(new java.awt.Font("Tahoma", 1, 24));
etiquetaHora.setForeground(new java.awt.Color(0, 0, 102));
etiquetaHora.setText("Actual time v.2.0.3.1");
panelHora.add(etiquetaHora);
textoHora.setHorizontalAlignment(javax.swing.JTextField.CENTER);
textoHora.setPreferredSize(new java.awt.Dimension(300, 20));
panelHoraTexto.add(textoHora);
panelHora.add(panelHoraTexto);
getContentPane().add(panelHora, java.awt.BorderLayout.CENTER);
getContentPane().add(panelVisorVideo, java.awt.BorderLayout.NORTH);
pack();
}// </editor-fold>
private void setIP(java.awt.event.ActionEvent evt) {
direccionIp = JOptionPane.showInputDialog(this, "Introduce la dirección del servidor: ", "Información", JOptionPane.INFORMATION_MESSAGE);
puerto = JOptionPane.showInputDialog(this, "Introduce el puerto del servidor: ", "Información", JOptionPane.INFORMATION_MESSAGE);
}
private void getVideo(java.awt.event.ActionEvent evt) {
ObjectInputStream canalEntrada;
InetAddress direccion = null;
Socket conexion = null;
if (direccionIp == null || puerto == null) {
JOptionPane.showMessageDialog(this, "Faltan datos de conexión", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
direccion = InetAddress.getByName(direccionIp);
conexion = new Socket(direccion, Integer.parseInt(puerto));
canalEntrada = new ObjectInputStream(conexion.getInputStream());
panelVideo aux = null;
try {
aux = (panelVideo) canalEntrada.readObject();
} catch (ClassNotFoundException ex) {
Logger.getLogger(GUIClienteVideo.class.getName()).log(Level.SEVERE, null, ex);
}
panelVisorVideo.add(aux);
aux.comenzar();
panelVisorVideo.updateUI();
System.out.println(aux);
} catch (ConnectException ex1) {
JOptionPane.showMessageDialog(this, "El servidor está desconectado", "Error", JOptionPane.ERROR_MESSAGE);
return;
} catch (UnknownHostException ex) {
Logger.getLogger(GUIClienteVideo.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(GUIClienteVideo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public class panelVideo extends JPanel implements Serializable{
String dispositivo;
Player player = null;
CaptureDeviceInfo di = null;
MediaLocator ml = null;
DataSource ds;
public panelVideo() {
// = ;
this.setSize(50,50);
di = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
ml = di.getLocator();
}
public void comenzar() {
try {
player = Manager.createRealizedPlayer(ml);
player.start();
Component comp = player.getVisualComponent();
if (comp != null) {
add(comp, BorderLayout.CENTER);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void parar() {
player.stop();
}
}
public class GUIServidorVideo extends javax.swing.JFrame implements Runnable {
private ServerSocket servidor;
Socket conexion;
Thread hiloServidor;
public GUIServidorVideo() {
initComponents();
}
private void setOn(java.awt.event.ActionEvent evt) {
hiloServidor = new Thread(this);
hiloServidor.start();
botonConectar.setEnabled(false);
botonDesconectar.setEnabled(true);
areaLog.append("El servidor se ha inicializado satisfactoriamente.\n");
}
private void setOff(java.awt.event.ActionEvent evt) {
try {
if(servidor != null){
servidor.close();
}else{
areaLog.append("El servidor no está inicializado.\n");
}
} catch (IOException ex) {
Logger.getLogger(GUIServidorVideo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void run() {
try {
servidor = new ServerSocket(7000);
while(true){
conexion = servidor.accept();
areaLog.append(">"+conexion.getInetAddress()+ " - " + conexion.getInetAddress().getHostName()+" ha realizado una petición\n");
HiloServidorVideo h = new HiloServidorVideo(conexion);
}
}catch (IOException ex) {
areaLog.append("El servidor a sido detenido.\n");
botonConectar.setEnabled(true);
botonDesconectar.setEnabled(false);
}
}
public class HiloServidorVideo extends Thread {
Socket conexion;
public HiloServidorVideo(Socket c){
conexion = c;
start();
}
public void run(){
ObjectOutputStream canalSalida = null;
panelVideo pVideo = new panelVideo();
try {
canalSalida = new ObjectOutputStream(conexion.getOutputStream());
} catch (IOException ex) {
Logger.getLogger(HiloServidorVideo.class.getName()).log(Level.SEVERE, null, ex);
}
try {
canalSalida.writeObject(pVideo);
/*
canalSalida.close();
conexion.close();
*/
} catch (IOException ex) {
Logger.getLogger(HiloServidorVideo.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Decir que, porsupuesto, tengo la clase panelVideo en el proyecto cliente y que es idéntica a la del servidor.
Gracias!
edit: también admito sugerencias para hacerlo de otra forma