本文介绍了当火炬手是奇怪的Andr​​oid摄像头的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的Andr​​oid code(这里写的伪code):

I have following android code (written here in pseudocode):

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();
}

有时(通常,当手机被最近重新启动和相机不使用到这个应用程序)这个code,错误100相机的服务器端死亡。如果相机成功地把照片前,它通常工作。

Sometimes (often when phone was recently restarted and camera wasn't in use until this app) this code ends with error 100 Camera server died. If camera took successfully picture before it usually works.

我调试它的时间大量的,我发现它的作品时,我注释掉火炬线。我能看到火炬在两种情况下拍照的作品,或不工作的时候。

I was debugging it for great amount of time and I found out it works when I comment out lines with torch. I can see torch working in both cases when taking pictures works or not.

torchOn的code为以下内容:

Code of torchOn is following:

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();
}

是否有任何理由拍照不能因为火炬的工作?我观察到它的发生摩托罗拉的Razr和三星Galaxy SIII。

Is there any reason why taking picture could not work because of torch? I observed it happend on Motorola Razr and Samsung Galaxy SIII.

我安装在我的装置里两个版本的这个程序(用不同的名称等)。而我下面的:

I installed on my device two version of this app (with different name and so on). And I do following:

  1. 重新启动设备
  2. 在尝试应用与 - 火炬
  3. 如果应用程序与 - 火炬确实工作早在1点。
  4. 在尝试应用且不火炬
  5. 在尝试应用与 - 火炬

和结果如下:

  1. 应用且不火炬的作品总是
  2. 应用与 - 圣火在约80%的尝试不点2(重启后)的工作
  3. (应用程序且不火炬使用后)
  4. 应用与 - 火炬的作品总是5点在
  1. App-without-torch works always
  2. App-with-torch in about 80% of tries doesn't work at point 2. (after restart)
  3. App-with-torch works always at point 5. (after app-without-torch was used)

我的应用程序启动,即使我想补充torchOff(工作)之前拍照。

My app start working even if I add torchOff() just before taking picture.

推荐答案

我们可以称之为巨蟒死鹦鹉Log.d答案:-PI希望我有你的解决方案 - 确实有一些建议,但。 Heisenbugs是很难赶上。

We could call this the " Monty Python Dead Parrot Log.d answer " :-P I wish I had a solution for you - do have some suggestions though. Heisenbugs are difficult to catch.

请问火炬有ISON()测试?
类似的(我不记得),确实相机有isReady()测试?

Does the torch have an isOn() test ?
Similarly (I don't recall), does the camera have an isReady() test ?

您可以从日志判断相机去世之前,期间或mCamera.torchOn()或.torchOff()?在

Can you tell from the logs if the camera dies before, during, or after mCamera.torchOn() or .torchOff() ?

你会,如果你伸出调用之间的时间跨度发生的呢?这将无法用于真正的应用程序,但可能会帮助您监控和捕捉发生了什么。说这句话的伪code:

What would happen if you stretch out the time span between calls ? This wouldn't be useable for the real app, but might help you monitor and catch what's happening. Say something like this 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() );   
  }

另外要监控,或者确保的是,摄像头和火炬真的准备好了的onClick之前可以开火。撒上一些延迟,如Log.d的四周看​​看。它可能需要一个回调(mCamera.isReady(),然后允许的onClick)。

The other thing to monitor, or make sure of, is that the camera and torch really are ready before that onClick can fire. Sprinkle some delays like the Log.d's all around and see. It might need a call back (mCamera.isReady() then enable onClick ).

另一件事就是看你能不能挖掘相机的源$ C ​​$ C(或火炬的)和grep错误100 - ?或者是一个通用的机器人100

Another thing to do is see if you can dig up the camera's source code (or the torch's) and GREP for error 100 - or is that a generic android 100 ?

我敢肯定,你也知道有多少事情发生时相机被炒鱿鱼了 - 好像上百个电话。由于一些低级别的项目是异步(CAM是硬件毕竟),我怀疑你得到NPE或不足初始化的对象。并不是所有的NPE的等深陷,所以它可能只是死在一个不会存在,如果延迟或syncronized序列使用。

I'm sure you're well aware of how much stuff happens when that camera gets fired up - seems like hundreds of calls. Since some of these low level items are async (cam is hardware after all), I suspect you're getting a NPE or a insufficiently initialized object. Not all NPE's etc get trapped, so it might just die on one that would not be there if delayed or syncronized sequences are used.

(HTH - 。我觉得你的疼痛,急性呼吸道感染,我不得不做了很多摄像头的东西最近调试三星SIII是过于耗时)

( HTH - I feel your pain, ari, I had to do a lot of camera stuff recently. Debugging on Samsung SIII is prohibitively time consuming. )

你可能已经发现了这种联系,但以防万一:

you've probably already found this link, but just in case:

How打开相机闪光灯以编程方式在Android的?

这篇关于当火炬手是奇怪的Andr​​oid摄像头的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:00