0
votes

I am developing a Google Glass app that uses a live card and a SurfaceView that runs in the background. What I'm trying to do is to create a dummy SurfaceView inside my custom view that the live card is rendering with DirectRenderingCallback. I have referenced the project in comment #3 and it works, but the difference is that I am not using any Activities to create the SurfaceView (if that matters).

I'm running into the issue where every time I try to start the camera preview, I get a message saying "app passed a NULL surface". I don't know whether it is because I'm creating the SurfaceView inside a service or not, but I just cannot seem to be able to get it working. Also, surfaceCreated() is never called.

As far as I know, there is nothing wrong with my code, or how I have set up the live card. I have been through the glass documentation and all of the GDK samples on their Github page. To sum it up, I'm trying to get the stream from the camera into a SurfaceView by using a Live Card. Am I doing anything wrong, or should I be doing something different to accomplish this?

Thanks.

1

1 Answers

1
votes

Well, in my project it is "half-working" as I can display an image but the red and blue colors are swapped, I still have no idea why.

So what I do is in a clas:

public class CameraView extends SurfaceView implements SurfaceHolder.Callback{

I create the surface, then on surfaceCreated open the camera and prepare the parameters:

    camera = Camera.open();
    Parameters parameters = camera.getParameters();
    parameters.setPreviewFpsRange(30000, 30000);            
    camera.setParameters(parameters);   

On surfaceChanged set the display and start the preview:

    if (camera != null){                    
        try {
            camera.setPreviewDisplay(holder);
        } catch (IOException e) {
            this.releaseCamera();
        }
        camera.startPreview();
    }

And this has worked for me, hope it helps!