I'm making an Android app using the Camera2 api.
I want to be able to switch between the front and back camera, but it takes an awful lot of time to do so no matter how i try to implement it.
After what i understand, you can't open both cameras at once(i've tried that also), so you have to stop the first one before opening the second.
The problem is it takes me 1.5seconds to stop the first camera.
How does for instance snapchat manage to swap the cameras in a few hundred milliseconds?
The code i'm using is the camera2basic from google that can be found here:
I've added a simple method to stop the camera:
public void stopCamera(){
Log.i("yoyo","Stopcamera() begin");
mCameraDevice.close();
//stopBackgroundThread();
Log.i("yoyo","Stopcamera() end");
}
Android Monitor:
08-01 15:13:01.478 10020-10020/com.example.android.camera2basic I/yoyo: Stopcamera() begin 08-01 15:13:02.852 10020-10020/com.example.android.camera2basic I/yoyo: Stopcamera() end 08-01 15:13:02.853 10020-10020/com.example.android.camera2basic I/Choreographer: Skipped 81 frames! The application may be doing too much work on its main thread. 08-01 15:13:02.855 10020-10207/com.example.android.camera2basic I/yoyo: Cameradevice - onClosed() callback running
-UPDATE 07 aug 2017-
It seems that the camera2 api just takes longer to shut down than the old camera api.
I tried using the old camera api and I achieved the same speed as snapchat/instagram, so i'm guessing they are using the old camera api.