Skip to content Skip to sidebar Skip to footer

How To Effectively Re-start The Preview Having Taken A Photo Inside An Android App?

I am attempting to code a tool that takes pictures at a dedicated interval (like a timelapse) and am having difficulty getting the camera to reset following the first capture so th

Solution 1:

takePicture() starts the capture process which ends with an (asynchronous) call to onPictureTaken() callback. You should not release camera before it is over.

So the pseudo-code that will perform a loop look like this:

onCLick() { // <-- start the loop
  count = 0;
  takePicture()
}

onPictureTaken() {
  savePicture(count);
  count++;
  if (count < maxCount) {
      mCamera.startPreview();
      mHandler.postDelayed(runTakePicture(), 1000);
  }
  else {
      releaseCamera();
  }
}

runTakePicture() {
   returnnewRunnable() {
      publicvoidrun() {
        mCamera.takePicture();
      }
   }
}

Post a Comment for "How To Effectively Re-start The Preview Having Taken A Photo Inside An Android App?"