Close CameraDevice in a seperate thread

后端 未结 2 920
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 02:24

I am using Android camera2 to create a custom camera. The cameraDevice.close() method is slow and it makes UI freeze for 1 sec. I put it in another thread and it seems to work j

2条回答
  •  鱼传尺愫
    2021-01-26 02:56

    As far as I know, such freeze with cameraDevice.close() happens on some unfortunate devices, and sometimes is cured by performing a normal system upgrade.

    But this is a little consolation if this happens to you, on your device. Actually, you are kind of lucky that you can prepare a fix for that. The end-users of your app will benefit from your misfortune.

    Your code looks OK, if it delivers desired improvements for you. As I explained, it may be hard to reproduce this problem on another device.

    I would rather put all closeCamera() logic on the same background thread. If you provided a Handler to openCamera(), as in the official example,

    manager.openCamera(mCameraId, mStateCallback, mBackgroundHandler);
    

    then I would suggest posting all closeCamera() sequence to this mBackgroundHandler.

提交回复
热议问题