问题
We are getting such stacktraces in our application using cwac-camera:
java.lang.IllegalStateException: Preview mode must have started before you can take a picture
at com.commonsware.cwac.camera.CameraView.takePicture(CameraView.java:329)
at com.commonsware.cwac.camera.CameraView.takePicture(CameraView.java:277)
at com.github.randoapp.camera.RandoCameraHost.onAutoFocus(RandoCameraHost.java:119)
at com.commonsware.cwac.camera.CameraView.onAutoFocus(CameraView.java:411)
at android.hardware.Camera$EventHandler.handleMessage(Camera.java:824)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
at dalvik.system.NativeStart.main(Native Method)
We believe that this can be happenning because of users pressing take picture too early. The solution is to disable button while preview is initializing and enable only when it's done. The question is: What event to use for button enabling? Is there event or callback sayong that preview is finally initialized?
回答1:
We believe that this can be happenning because of users pressing take picture too early
That is a distinct possibility.
What event to use for button enabling? Is there event or callback sayong that preview is finally initialized?
autoFocusAvailable()
in your CameraHost
is the best option at the moment. That is called just before the preview begins and inPreview
is set to true
.
I have filed an issue to do a better job than this.
回答2:
We got this exception whenever automatic flash was used while taking a picture in poor light conditions.
We "fixed" it by removing the inPreview
check in CameraView (line 284)
, but I'm not sure if that wouldn't create other problems (I guess the check was there for a reason), but we haven't got any since.
来源:https://stackoverflow.com/questions/24456715/preview-mode-must-have-started-before-you-can-take-a-picture