JMFのメディアライブラリを使用してJavaでWebカメラを使用している開発中のアプリケーションで問題が発生した場合、誰かが私を助けてくれることを願っていました。Java Webcam GUIアプリケーション
私が午前問題は、私は私が望む私のGUIアプリケーションにそれを置くとき、私はしかし、ここで、このクラスで自身によってアプリケーションでOK
import java.awt.BorderLayout;
import java.util.Vector;
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.media.control.FormatControl;
import javax.swing.JFrame;
import javax.swing.JButton;
public class WebcamClass{
CaptureDeviceInfo cam;
MediaLocator locator;
Player player;
FormatControl formatControl;
public WebcamClass(){
try{
// List out available Devices to Capture Video.
Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList (null);
System.out.println(list);
// Iterating list
for(CaptureDeviceInfo temp : list){
// Checking whether the current device supports VfW
// VfW = Video for Windows
if(temp.getName().startsWith("vfw:"))
{
System.out.println("Found : "+temp.getName().substring(4));
// Selecting the very first device that supports VfW
cam = temp;
System.out.println("Selected : "+cam.getName().substring(4));
break;
}
}
System.out.println("Put it on work!...");
// Getting the MediaLocator for Selected device.
// MediaLocator describes the location of media content
locator = cam.getLocator();
if(locator != null){
// Create a Player for Media Located by MediaLocator
player = Manager.createRealizedPlayer(locator);
if(player != null){
// Starting the player
player.start();
// Creating a Frame to display Video
JFrame f = new JFrame();
f.setTitle("Test Webcam");
f.setLayout(new BorderLayout());
// Adding the Visual Component to display Video captured by Player
// from URL provided by MediaLocator
f.add(player.getVisualComponent(), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
}catch(Exception e){
System.out.println(e);
}
}
}
をウェブカメラを実行することができますですそれを実行するには、ボタンを押してカメラをオンにすると、「スレッド内の例外」AWT-EventQueue-0「java.lang.NullPointerException」が発生し続けます。
私はそれが私のGUIに埋め込みしようとしていないときに私はなぜWebカメラデバイスをピックアップしていないが、私は理解できないと知っている。
私のライブラリフォルダにもJMF.jarがあります。
ご協力いただければ幸いです。