I'm trying to encode a tool that takes pictures at a selected interval (like timelapse), and it's hard for me to get the camera to reset after the first capture so that it can then start with the next photo.
Here is an example of the code used:
// gets called with the oncreate method and loads a preview fine public void startUpPreview(){ mCamera = getCameraInstance(); mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); preview.addView(mPreview); } // gets called from a later loop public void getPicture() { mCamera.takePicture(null, null, mPicture); releaseCamera(); startUpPreview(); }
Using the code above, it throws an error:
java.lang.RuntimeException: method called after release ()
I use release code taken directly from the SDK manual, which works differently:
private void releaseCamera(){ if (mCamera != null){ mCamera.release(); mCamera = null; } }
For one image adding delay with a sleep stream, it works:
try { Thread.sleep(1000); releaseCamera(); startUpPreview(); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); }
But this code does not work in a loop when trying to take a few shots. I assume the cycle ends before all these snapshots can catch up.
Thanks in advance for any help anyone can provide.
source share