Tuesday, 25 September 2018

How to use the UVCCamera library

I am trying to use UVCCamera in my application. This library has no good documentation on how to use it and just recommends referring to examples and their Japanese website. Currently, I am making use of this example. UVCCamera makes extensive use of multithreading and as far as I know, a special Android looper. The problem with the example is that it initiates the camera with a button which then triggers a DialogFragment and then allows the user to select a camera from the list. Next, it opens up a dialog requesting camera access permission (if not already granted). Finally, it opens up the camera preview. The extensive use of multithreading and Runnables in these components makes tracking the device difficult for a threading-novice like me. Not trying to say that I know nothing about threads and loopers and message queues. Simply, the library is very hard to understand. Nevertheless, I am able to get the current connected USB camera using the following code:

UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
        UsbDevice usbDevice = null;
        for(UsbDevice device : deviceList.values()) {
            if(device.getDeviceClass() == 239 && device.getDeviceSubclass() == 2) {
                usbDevice = device;
                break;
            }
        }

        if(usbDevice != null) {
            Log.d(TAG, "onCreate: usbDevice: " + usbDevice.toString());
        }

Does anyone know how I can pass in this device to the library to create the preview for. All I want to achieve for now is to auto-start the preview as soon as the camera is connected, eliminating the need for the user to press the button and initiate a camera dialog.



from How to use the UVCCamera library

No comments:

Post a Comment