Skip to content Skip to sidebar Skip to footer

Camera.setpreviewdisplay() Throws Exception

Possible Duplicate: Android Camera will not work. startPreview fails I am trying to set a camera preview in a custom SurfaceView but I get an exception each time I execute the i

Solution 1:

I completely agree with Jon Bright

I couldn't figure out what was going on for a week, I ignored the setType on the surface holder because the SDK said it was deprecated, ie.

"This method is deprecated. this is ignored, this value is set automatically when needed."

But if you don't do that, it will crash on setPreview. This is running 1.5 SDK (I need it to be backwards compatible to that) on a Galaxy S with 2.1. So make sure you set the type. Not quite as automatic as the documentation makes it sound.

Solution 2:

The best place to call setPreviewDisplay() is in surfaceChanged() If the surface is just created, surfaceChanged will be called at least once and you can startPreview() and setPreviewDisplay there. If the surface changes and the preview already starts, you can stopPreview/setPreviewDisplay/startPreview there. Even if your app does not change the size of the surface, the framework may still unexpectedly call surfaceChanged() when the app starts or exits due to orientation changes. So your app really needs to handle surfaceChanged properly. You can trace the source code of camera application in Android for reference.

The code snippet in another answer works if surfaceChanged() is only called once in the app lifecycle.

Post a Comment for "Camera.setpreviewdisplay() Throws Exception"