saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
2.96k stars 1.19k forks source link

Start preview automatically #576

Open NhiemHK opened 3 years ago

NhiemHK commented 3 years ago

How to start preview automatically after first usb camera attached? There is no need to show dialog to select devices because I only need one camera plugged in. Help me, please!

EjazAmir commented 3 years ago

How to start preview automatically after first usb camera attached? There is no need to show dialog to select devices because I only need one camera plugged in. Help me, please!

hey, did you find any solution for this?

Guizzz commented 3 years ago

Yes, i have done it! I write this little function that open the first camera that he find. Add it into libusbcamera/com/serenegiant/usb/CameraDialog.java inside the CameraDialog Class. `

    public Object getCamera() 
    {
    updateDevices();

    final List<DeviceFilter> filter = DeviceFilter.getDeviceFilters(getActivity(), R.xml.device_filter);

    mDeviceListAdapter = new DeviceListAdapter(getActivity(), mUSBMonitor.getDeviceList(filter.get(0)));

    Log.v(TAG,mDeviceListAdapter.getItem(0).getDeviceName());

    this.dismiss();

    return mDeviceListAdapter.getItem(0);

}

`

And then add these two lines into onCreateDialog function on the same file, before the return.

`

           mUSBMonitor.requestPermission((UsbDevice) getCamera());

           ((CameraDialogParent)getActivity()).onDialogResult(false);`

It looks like this:

`

  @Override
      public Dialog onCreateDialog(final Bundle savedInstanceState) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(initView());
            builder.setTitle(R.string.select);
        builder.setPositiveButton(android.R.string.ok, mOnDialogClickListener);
        builder.setNegativeButton(android.R.string.cancel , mOnDialogClickListener);
        builder.setNeutralButton(R.string.refresh, null);
        final Dialog dialog = builder.create();
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);

    mUSBMonitor.requestPermission((UsbDevice) getCamera());
    ((CameraDialogParent)getActivity()).onDialogResult(false);

    return dialog;
}`

Of course this is not the best solution but it's work!

chanakamendi commented 2 years ago

@Guizzz it doesn't work

Guizzz commented 2 years ago

I honestly don't understand why the code section in my comment is badly indented and maybe you don't understand. I updated the comment and i tried to fix it. I'm sorry but I don't know how to help you more than that. Also i moved to another solution, this was just a work-around for me.

chanakamendi commented 2 years ago

@Guizzz
i really need is when re enter to the activity it should connect camera automatically and show the preview . but when i re enter i get "conntecting" message from "onConnectDev(UsbDevice device, boolean isConnected)" but i dont get preview . so if i disconnect the camera and connect again it work

Guizzz commented 2 years ago

I really sorry but like i said i moved to another solution and this lib i don't neither remember how it is works

chanakamendi commented 2 years ago

what is your another lib?