java - Camera flash blinking stalls app -
i want add new feature app: created progress bar , every time progress changes, flash blink delay equal value of progress in milliseconds.
when modify progress, flash begins blink can't until reaches number of blinks (20). want able modify delay if flash still blinking.
private void blink(int sleepms) throws exception{ //int sleepms=(1/10)*50; int flashcount=20; getcamera(); camera.setpreviewtexture(new surfacetexture(0)); camera.startpreview(); thread thr = new thread(); thr.start(); for(int i=0;i<flashcount;i++) { flipflash(); thr.sleep(sleepms); flipflash(); thr.sleep(sleepms); } camera.stoppreview(); //camera.release(); } private void flipflash(){ if (isflashon) { params.setflashmode(camera.parameters.flash_mode_off); camera.setparameters(params); isflashon = false; } else{ params.setflashmode(camera.parameters.flash_mode_torch); camera.setparameters(params); isflashon = true; } }
where getcamera()
gets camera parameters. , code seekbar
listener:
volumecontrol = (seekbar) findviewbyid(r.id.volume_bar); volumecontrol.setonseekbarchangelistener(new seekbar.onseekbarchangelistener() { int progresschanged = 0; public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { progresschanged = progress; } public void onstarttrackingtouch(seekbar seekbar) { // todo auto-generated method stub } public void onstoptrackingtouch(seekbar seekbar) { try { blink(100 - progresschanged); } catch (exception e) { } } });
because loop on main thread blocking other operations. code, seems meant this:
thread thr = new thread(new runnable() { @override public void run() { for(int i=0;i<flashcount;i++) { flipflash(); thr.sleep(sleepms); flipflash(); thr.sleep(sleepms); } } }); thr.start();
Comments
Post a Comment