Reputation: 4239
How to detect whether the Web cam is attached to computer or not by using Java?
Upvotes: 2
Views: 3620
Reputation: 13950
Here is a piece of code I use in a simple Webcam client with JMF:
Format format = new RGBFormat();
MediaLocator cameraLocator = null;
// get device list
Vector deviceList = CaptureDeviceManager.getDeviceList(format);
// if devices available
if(deviceList != null && deviceList.size() > 0) {
// pick first
CaptureDeviceInfo device = (CaptureDeviceInfo) deviceList.get(0);
cameraLocator = device.getLocator();
}
It picks the first available webcam. Of course, after having the webcam you can store the cameraLocator and try to re-open it on the 2nd run.
Upvotes: 0
Reputation: 1323343
JMF (Java Media Framework) should be able to detect any media, including a webcam.
Potentially through CaptureDeviceManager.getDeviceList();
For "installing JMF on Linux", one way is simply to:
:
% /bin/sh ./jmf-2_1_1e-linux-i586.bin
Upvotes: 2