I am writing strobe light for android. Samsung galaxy ace does not support flash mode. So I wrote it on my own. Here is the code that I use to make it a strobe light. But it blocks the main thread of the android application (UI thread), which I do not want to do. When I insert this code into a new thread and run it, the inclusion period is longer when I measure it. Why is this so?
Camera cam = Camera.open(); Camera.Parameters pon = cam.getParameters(); Camera.Parameters poff = cam.getParameters(); while(true) { try { //d = new Date(); //System.out.println("ON START " + d.getSeconds()); cam.setParameters(pon); //because FLASH_MODE_TORCH isnt supported pon.setFlashMode(Camera.Parameters.FLASH_MODE_ON); pon.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY); s1.start(); cam.startPreview(); cam.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { camera.autoFocus(this); } }); Thread.sleep(500); //d = new Date(); s1.stop(); System.out.println("ON FOR milliseconds : " + s1.getElapsedTime()); cam.stopPreview(); s2.start(); Thread.sleep(500); s2.stop(); System.out.println("OFF FOR milliseconds : " + s2.getElapsedTime()); } catch (InterruptedException e) { e.printStackTrace(); } }
I just paste the above code into a new runnable and say start, the ON period is longer when it is inserted into the stream. Elapsed time - in milliseconds.
source share