om.
om.

Reputation: 4239

How to detect Web Cam is attached or not Using java

How to detect whether the Web cam is attached to computer or not by using Java?

Upvotes: 2

Views: 3620

Answers (2)

cringe
cringe

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

VonC
VonC

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:

  • download it.
  • Change directories to the install location.
  • Run the command

:

  % /bin/sh ./jmf-2_1_1e-linux-i586.bin 

Upvotes: 2

Related Questions