Wednesday, June 20, 2012

android::CameraHardwareSec::takePicture() : capture already in progress error

Today, One of the Android devices keep getting crashed while taking a picture in a TimerTask. I was keep getting this error


E/CameraHardwareSec(75): virtual android::status_t android::CameraHardwareSec::takePicture() : capture already in progress
E/PanicImageActivity(1750): java.lang.RuntimeException: takePicture failed


problem is before you call this method again in the TimerTask run method. you need to make sure that there is one not in progress. Some devices cameras are very slow on processing picture frames.


private final Semaphore mutex = new Semaphore(1);



try {

mutex.acquire();


mCamera.takePicture(null, null, new PictureCallback() { 
        public void onPictureTaken(byte[] data, Camera camera) {
try {
             // Do something here
              mutex.release();
         }

         catch(Throwable t) {
          mutex.release();
         }

});
}
catch (Throwable t) {

 }

No comments:

Post a Comment