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;
	}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值