Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 743
DominicM Avatar asked May 28 '12 14:05

DominicM


2 Answers

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.

like image 187
yigit Avatar answered Sep 29 '22 07:09

yigit


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

like image 20
Konstantin Pribluda Avatar answered Sep 29 '22 06:09

Konstantin Pribluda