PDA

View Full Version : [Java] Media Framework - La webcma non ne vuole proprio sapere!


GreatSlug
29-03-2009, 14:40
Salve ragazzi,
in una solo parola DISPERATO!
devo far funzionare la mia webcam (logitech QuickCam for Notebook) in un'applicazione java, decido dunque di usare jmf.
Cercando su internet trovo alcuni tutorial tra i quali questo:
http://eqepa.blogspot.com/2008/11/java-media-framework-eqepa-tutorial-2.html
dico Perfetto! io uso per altro netBeans fa proprio al caso mio! quindi apro il progetto e lo eseguo e tac ecco gli errori:

run:
main
setmedialocator
mediaLocator settato
problema nel settaggio del player
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at webcam_eqepa.Main.settaggioPlayer(Main.java:71)
at webcam_eqepa.Main.<init>(Main.java:79)
at webcam_eqepa.Main$1.run(Main.java:89)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
BUILD SUCCESSFUL (total time: 1 second)

Mi dico va beh! troppo bello sarebbe stato, allora cerco di studiare il problema e faccio un'altra classe che chiamo camInterface in cui metto tutto il contenuto della classe main meno il void main che lascio nella classe main del programma; fatto questo creo dentro il void main un'istanza della classe camInterface e gli eseguo il comando c.setVisible(true) ma dinuovo ecco gli errori:

init:
deps-jar:
compile:
run:
main
setmedialocator
mediaLocator settato
problema nel settaggio del player: javax.media.NoPlayerException: Cannot find a Player for :vfw://0
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1027)
at java.awt.Container.add(Container.java:352)
at webcam_eqepa.camInterface.<init>(camInterface.java:44)
at webcam_eqepa.Main.main(Main.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

ho provato altre milioni di soluzioni ma niente...
qui di seguito vi scrivo il codice del cam interface e del ContenitoreManiglie e del Main (scusate se sono prolisso)

camInterface:
PS scusate per il minestrone che ho fatto nel costruttore :ciapet:

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.io.IOException;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JFrame;

/**
*
* @author Giuseppe
*/
public class camInterface extends JFrame{
MediaLocator mediaLocator;
Player player;
Component comp = null;
Container ContentPane = this.getContentPane();
MyControllerListener MyCL = new MyControllerListener();

public camInterface() throws IOException, NoPlayerException{
System.out.println("main");
//this.settaggioInferfaccia();
ContenitoreManiglie.setMain(this);
setLayout(new BorderLayout());

//this.settaggioPlayer();
System.out.println("setmedialocator");
mediaLocator = new MediaLocator("vfw://0");
System.out.println("mediaLocator settato");
try{
player=Manager.createPlayer(mediaLocator);
player.start();
} catch(Exception e){System.out.println("problema nel settaggio del player: "+e);
}
this.ContentPane.add(comp);
ContenitoreManiglie.setMain(this);
comp=this.player.getVisualComponent();
add(comp,BorderLayout.NORTH);
this.pack();
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

}

public void setComponentiVisuali(){

comp=player.getVisualComponent();
add(comp,BorderLayout.NORTH);
this.pack();
}
}


ContenitoreManiglie:

public final class ContenitoreManiglie {

private static camInterface M;

public static void setMain(camInterface m){

ContenitoreManiglie.M=m;

}

public static camInterface getMain(){
return ContenitoreManiglie.M;

}

}


Main

import java.io.IOException;
import javax.media.NoPlayerException;

/**
*
* @author santennio
*/
public class Main{


public static void main(String args[]) throws IOException, NoPlayerException {
camInterface cam = new camInterface();
cam.setVisible(true);
}
}


A ovviamente sono tanto accanito e infuriato perchè il JMstudio di Java riesce benissimo ad utilizzare la WebCam ed io NOOO ! :muro: :muro: :muro:
Ragazzi aiutatemi vi ringrazio chiunque risponderà!

Sant'Ennio
19-04-2009, 13:28
Ciao, sembra che non riesce a trovare il device a partire dalla stringa "vfw://0". Hai provato a vedere se il locator della webcam (da jmfregistry.exe) è effettivamente quello? Se non è lo stesso prova a cambiarlo.