在退出线程后的代码中,闪光灯仍然亮着。我无法理解逻辑错误。如何在线程末端关闭闪光灯?
Thread thread = new Thread((new Runnable() {
@Override
public void run() {
SystemClock.sleep(200);
int led = 1;
while (blink_enabler) {
if (led == 1) {
params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
cam.setParameters(params);
cam.startPreview();
led = 0;
} else {
params = cam.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(params);
cam.stopPreview();
led = 1;
}
SystemClock.sleep(1000);
}
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.stopPreview();
}
}));
答案 0 :(得分:0)
在while循环之后,在stopPreview()
:
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
cam.setParameters(params);
cam.stopPreview();