我尝试在applet上使用JMF从网络摄像头读取数据。但在下面的代码中:
String str2 =“ vfw:Microsoft WDM图像捕获(Win32):0”;di = CaptureDeviceManager.getDevice(str2);ml = di.getLocator();
Capturedevicemanager.getdevice(str2);
方法返回null值。
tnx
在调用CaptureDeviceManager.getDeviceList()之前,必须先将可用设备加载到内存中。
您可以在安装JMF之后通过运行JMFRegistry手动进行操作。
或借助于扩展库FMJ(Java中的Free Media)以编程方式进行。这是代码:
import java.lang.reflect.Field;
import java.util.Vector;
import javax.media.*;
import javax.media.format.RGBFormat;
import net.sf.fmj.media.cdp.GlobalCaptureDevicePlugger;
public class FMJSandbox {
static {
System.setProperty("java.library.path", "D:/fmj-sf/native/win32-x86/");
try {
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
GlobalCaptureDevicePlugger.addCaptureDevices();
Vector deviceInfo = CaptureDeviceManager.getDeviceList(new RGBFormat());
System.out.println(deviceInfo.size());
for (Object obj : deviceInfo ) {
System.out.println(obj);
}
}
}
这里是输出:
USB2.0 Camera : civil:\\?\usb#vid_5986&pid_02d3&mi_00#7&584a19f&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global
RGB, -1-bit, Masks=-1:-1:-1, PixelStride=-1, LineStride=-1