setTorchMode非常慢,我怎样才能加快通话速度?

时间:2017-02-02 23:19:24

标签: java android performance

我需要在特定时间闪光相机手电筒,理想情况下每0.5秒精度约2ms。有了音频,我已经很好地管理了但是对setTorchMode的调用似乎需要接近1/2。我试图将调用放在Runnable中,但是(正如预期的那样)创建了一个积压。以下是我的时间测量:

  public void doFlash() {
        if (cameraManager == null) return;
        try {
            Log.d(TAG,"1="+System.nanoTime()/1000000);
            cameraManager.setTorchMode(cameraId, true);
            Log.d(TAG,"2="+System.nanoTime()/1000000);
            yield();
            Log.d(TAG,"3="+System.nanoTime()/1000000);
            cameraManager.setTorchMode(cameraId, false);
            Log.d(TAG,"4="+System.nanoTime()/1000000);
            Log.d(TAG,"-------------");
        } catch (Exception e) {
            Log.d(TAG, "Could not switch on flash");
        }
    }
}

02-02 23:06:57.950 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:1 = 1662873286 02-02 23:06:58.668 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:2 = 1662874004 02-02 23:06:58.668 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:3 = 1662874004 02-02 23:06:59.149 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:4 = 1662874484 02-02 23:06:59.149 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:------------- 02-02 23:06:59.149 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:1 = 1662874484 02-02 23:06:59.649 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:2 = 1662874985 02-02 23:06:59.649 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:3 = 1662874985 02-02 23:07:00.074 17528-17792 / tech.glasgowneuro.attyseeg D / EPFragment:4 = 1662875409

我很困惑为什么这个功能需要这么长时间?是否有更快的其他呼叫或如何在2ms或更短的时间内完成?

1 个答案:

答案 0 :(得分:0)

我是第二个 - 它需要1/3到1秒(三星Galaxy S7)。与旧的#34;相机相比,#34;如果你想眨眼,这是无法使用的......