FileDocCategorySizeDatePackage
CaptureDeviceManager.javaAPI DocJMF 2.1.1e6578Mon May 12 12:20:36 BST 2003javax.media

CaptureDeviceManager

public class CaptureDeviceManager extends Object
CaptureDeviceManager is a manager class that provides access to a list of the capture devices available on a system. CaptureDeviceManager uses a registry and query mechanisms to locate devices and return CaptureDeviceInfo objects for available devices. The CaptureDeviceManager is also used to register new capture devices.
since
JMF 2.0

Fields Summary
private static CaptureDeviceManager
cdm
private static Method
mGetDeviceList
private static Method
mGetDevice
private static Method
mAddDevice
private static Method
mRemoveDevice
private static Method
mCommit
Constructors Summary
Methods Summary
public static booleanaddDevice(javax.media.CaptureDeviceInfo newDevice)
Adds a CaptureDeviceInfo object for a new capture device to the list of devices maintained by the CaptureDeviceManager. This information is not stored permanently in any registry unless commit is called.

param
newDevice A CaptureDeviceInfo object that identifies the new device.
see
#commit
return
true if the object is added successfully, false if it is not.

	if (cdm != null && mAddDevice != null) {
	    Object params[] = new Object[1];
	    params[0] = newDevice;
	    Object result = runMethod(mAddDevice, params);
	    if (result != null)
		return ((Boolean)result).booleanValue();
	    else
		return false;
	} else
	    return false;
    
public static voidcommit()
Permanently stores information about the list of devices in the registry. Commit must be called to save changes made to the device list by calling addDevice or removeDevice.

exception
IOException If the registry could not be committed to disk due to an IO error.

	if (cdm != null && mCommit != null) {
	    runMethod(mCommit, null);
	}
    
public static javax.media.CaptureDeviceInfogetDevice(java.lang.String deviceName)
Gets a CaptureDeviceInfo object that corresponds to the specified device.

param
deviceName A String that contains the name of the device for which you want to get a CaptureDeviceInfo object. For example: "SunVideo".
return
A CaptureDeviceInfo object that corresponds to the specified device name. Returns null if the specified device could not be found.

	if (cdm != null && mGetDevice != null) {
	    Object params[] = new Object[1];
	    params[0] = deviceName;
	    return (CaptureDeviceInfo) runMethod(mGetDevice, params);
	} else
	    return null;
    
public static java.util.VectorgetDeviceList(javax.media.Format format)
Gets a list of CaptureDeviceInfo objects that correspond to devices that can capture data in the specified Format. If no Format is specified, this method returns a list of CaptureDeviceInfo objects for all of the available capture devices.

return
A Vector that contains CaptureDeviceInfo objects for the devices that support the specified Format.

	if (cdm != null && mGetDeviceList != null) {
	    Object params[] = new Object[1];
	    params[0] = format;
	    Vector returnVal = (Vector) runMethod(mGetDeviceList, params);
	    if (returnVal == null)
		return new Vector(1);
	    else
		return returnVal;
	} else
	    return new Vector(1);
    
public static booleanremoveDevice(javax.media.CaptureDeviceInfo device)
Removes a CaptureDeviceInfo object from the list of devices maintained by the CaptureDeviceManager. The change is not stored permanently in any registry unless commit is called.

param
device A CaptureDeviceInfo object that identifies the device to remove.
see
#commit
return
true if the object is removed successfully, false if it is not.

	if (cdm != null && mRemoveDevice != null) {
	    Object params[] = new Object[1];
	    params[0] = device;
	    Object result = runMethod(mRemoveDevice, params);
	    if (result != null)
		return ((Boolean)result).booleanValue();
	    else
		return false;
	} else
	    return false;
    
private static java.lang.ObjectrunMethod(java.lang.reflect.Method m, java.lang.Object[] params)


     
	// Look for javax.media.cdm.CaptureDeviceManager
	try {
	    Class classCDM = Class.forName("javax.media.cdm.CaptureDeviceManager");
	    if (classCDM != null) {
		Object tryCDM = classCDM.newInstance();
		if (tryCDM instanceof CaptureDeviceManager) {
		    cdm = (CaptureDeviceManager) tryCDM;
 		    mGetDeviceList =
 			PackageManager.getDeclaredMethod(classCDM,
                              "getDeviceList",
			       new Class[] {Format.class});

 		    mGetDevice =
 			PackageManager.getDeclaredMethod(classCDM,
                              "getDevice",
			       new Class[] {String.class});

 		    mCommit =
 			PackageManager.getDeclaredMethod(classCDM,
                              "commit", null);

 		    mAddDevice =
 			PackageManager.getDeclaredMethod(classCDM,
                              "addDevice",
			       new Class[] {CaptureDeviceInfo.class});
					       
 		    mRemoveDevice =
 			PackageManager.getDeclaredMethod(classCDM,
                              "removeDevice",
			       new Class[] {CaptureDeviceInfo.class});
		}
	    }
	} catch (ClassNotFoundException cnfe) {
	    System.err.println(cnfe);
	} catch (InstantiationException ie) {
	    System.err.println(ie);
	} catch (IllegalAccessException iae) {
	    System.err.println(iae);
	} catch (SecurityException se) {
	    System.err.println(se);
	} catch (NoSuchMethodException e) {
	    System.err.println(e);
	}
    
	try {
	    return m.invoke(null, params);
	} catch (IllegalAccessException iae) {
	    System.err.println(iae);
	} catch (IllegalArgumentException iare) {
	    System.err.println(iare);
	} catch (InvocationTargetException ite) {
	    System.err.println(ite);
	}
	return null;