Strange Android camera behavior when the torch opens

I have the following Android code (written here in pseudo code):

mCamera = configAndInitialize(); //all I want to do before taking picture
mCamera.startPreview();
mCamera.torchOn(); //setting parameters with flash mode torch

onClick(){
    mCamera.stopPreview();
    mCamera.takePicture();
    mCamera.torchOff();
}

Sometimes (usually the phone is restarted recently and the camera is not used before this application) this code ends with error 100 and the camera server dies. If the camera takes pictures successfully before it normally works

I've been debugging it for a long time. When I annotated the drop bar with the torch, I found it effective. I can see that the torch can work normally in both cases

The torch code is as follows:

if(mCamera != null){
    mCamera.stopPreview();
    Camera.Parameters p = mCamera.getParameters();
    List<String> supported = p.getSupportedFlashModes();
    if (supported.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
      p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    }
    mCamera.setParameters(p);
    mCamera.startPreview();
}

Is there any reason why the torch photography can't work? I observed that it happened on Motorola Razr and Samsung Galaxy SIII

I installed two versions of this application (with different names, etc.) on my device. I did the following:

>Restart the device > try to use the torch bearer > If app with torch does work at point 1. > try an application without torch > try to use the torch bearer

The results are as follows:

>App without torch always works > app torch in about 80% of attempts does not work at point 2. (after restart) > app with torch always works at point 5. (after using app without torch)

Even if I added torch off () before taking photos, my app will start working

resolvent:

We can call it "Monty Python dead parrot log. D answer": - P I hope I have a solution - despite some suggestions. Heisenbugs is difficult to capture

Is there an ison () test for the flare? Also (I don't remember), does the camera have an isready () test?

You can judge from the log whether the camera died before, during or after mcamera. Torchon() or. Torchoff()?

What happens if you extend the time interval between calls? This does not apply to real applications, but may help you monitor and capture what is happening. Say something similar in pseudo code:

  try {
    // Log.d ("cam", "here 1") ;
    mCamera = configAndInitialize();
    // Log.d ("cam", "here 2");
    if ( mCamera.isReady() ) {  // or isConfigured / initialized 
       // Log.d ("cam", "here 2");
       Camera.startPreview();
       // Log.d ("cam", "here 2");
       thisThread.setDelay (200); // millisecs. try even up to 2000 ms !
       // Log.d ("cam", "here 4");
       mCamera.torchOn();
       // Log.d ("cam", "here 5");
       thisThread.setDelay (200); // again up to 2000 ms
       // Log.d ("cam", "here 6");
    }
  } catch (Exception e) {
    Log.d ("oops!", e.toString() );   
  }

Another thing to monitor or determine is that the camera and flashlight are really ready before onclick can be triggered. Spread some delays like log. D. see. It may need a callback (mcamera. Isread() and then enable onclick)

Another thing is to see if you can mine the camera's source code (or torch's) and grep's error 100 - or a generic Android 100?

I'm sure you know exactly what happens when the camera is lit - there seem to be hundreds of phones. Because some of the low-level items are asynchronous (after all, the cam is hardware), I suspect you get NPES or objects with insufficient initialization. Not all NPES are trapped, so if you use delay or synchronization sequences, it may die on those non-existent NPES

(HTH – I feel your pain, ARI. I have to do a lot of camera things recently. Debugging on Samsung SIII is very time-consuming.)

[editor] you may have found this link, but just in case:

How to turn on camera flash light programmatically in Android?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>