UVCCamera icon indicating copy to clipboard operation
UVCCamera copied to clipboard

Start preview automatically

Open NhiemHK opened this issue 4 years ago • 7 comments

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!

NhiemHK avatar Oct 24 '20 11:10 NhiemHK

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?

EjazAmir avatar Nov 03 '20 13:11 EjazAmir

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!

Guizzz avatar May 13 '21 14:05 Guizzz

@Guizzz it doesn't work

chanakamendi avatar Feb 10 '22 13:02 chanakamendi

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.

Guizzz avatar Feb 11 '22 08:02 Guizzz

@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

chanakamendi avatar Feb 11 '22 10:02 chanakamendi

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

Guizzz avatar Feb 11 '22 11:02 Guizzz

what is your another lib?

chanakamendi avatar Feb 14 '22 07:02 chanakamendi