JMF_1:获取设备列表
闲来无事,便想到研究一下JMF。
?
首先,下载JMF,安装。
打开eclipse,新建工程,注意要将你的JMF引入到工程的classpath中。
(在你的工程上右键->Build Path->Configure Build Path,在弹出的对话框中,选择Libraries->Add External JARs,在弹出的对话框中,选择JMF安装目录下的\lib,我是全部将下面的jar都选中了。)
?
新建一个类。加入如下方法(此代码网上有)。
唯一需要注意的是:
Format videoFormat = new VideoFormat(VideoFormat.RGB);Vector<CaptureDeviceInfo> deviceList = CaptureDeviceManager.getDeviceList(null);?
我之前是按照网上的写法:
Format videoFormat = new VideoFormat(VideoFormat.RGB);Vector<CaptureDeviceInfo> deviceList = CaptureDeviceManager.getDeviceList(videoFormat);?可是无论如何也取不到设备列表,后经多方查找,有人说将getDeviceList()的参数设为null即可,一试果然如此。但尚不知道原因,麻烦大家告知我一声吧。
?
public CaptureDeviceInfo getCaptureDeviceInfo() {Format videoFormat = new VideoFormat(VideoFormat.RGB);Vector<CaptureDeviceInfo> deviceList = CaptureDeviceManager.getDeviceList(null);if (deviceList.size() < 1) {JOptionPane.showMessageDialog(null, "No capture device be found","Error", JOptionPane.ERROR_MESSAGE);System.exit(0);}String[] deviceNames = new String[deviceList.size()];for (int i = 0; i < deviceNames.length; i++) {deviceNames[i] = deviceList.get(i).getName();}String deviceName = (String) JOptionPane.showInputDialog(null, "Pls choose video input device","Please Choose", JOptionPane.QUESTION_MESSAGE, null,deviceNames, deviceNames[0]);if (deviceName == null) {return null;} else {CaptureDeviceInfo deviceInfo;for (int i = 0; i < deviceNames.length; i++) {deviceInfo = deviceList.get(i);if (deviceName.equals(deviceInfo.getName())) {return deviceInfo;}}}return null;}??
Format videoFormat = new VideoFormat(VideoFormat.YUV);Vector<CaptureDeviceInfo> deviceList = CaptureDeviceManager.getDeviceList(videoFormat);