简体   繁体   中英

Android: onPreviewFrame never called without SurfaceView

On some devices, onPreviewFrame is not called if no SurfaceView was set to display the camera preview. However, I handle the camera in a service, so I can't set a SurfaceView but I don't want to have visible preview anyway.

How can this be done? Can I programmatically create a SurfaceView and set it with Camera::setPreviewDisplay ?

This must be possible or not?

It works on almost every phone without a SurfaceView but not on HTC One X and Google Nexus One...

According to this question , creating a SurfaceView in code works fine. Though I don't think you can create it through a service.

Another approach is to create a 1px-1px SurfaceView inside a RelativeLayout and hiding it with some other view on top of it. (visibility should still be VISIBLE ). We use this trick for Path camera UI where we render preview buffers through OpenGL and it works fine.

According to documentation readily configured, visible and displayed surface view is necessary to activate camera preview. It may be overlayued though

From API 11 on, you can use a SurfaceTexture instead of a SurfaceView to get frames from the camera. Then, instead of using Camera.setPreviewDisplay , simply use Camera.setPreviewTexture .

This answer as well as this one discuss this point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM