Android KitKat(4.x.x)'s PreviewCallback is must want SurfaceHolder?

67 Views Asked by At

I Have a Question.

Android KitKat(4.x.x)'s PreviewCallBack is must want SurfaceHolder?

Because My Preview project PreviewCallBack is work very well in Android 6.x, 7.0. And it doesn't use SurfaceHolder.

But My PreviewProject in KitKat, PreviewCallBack does't hit CallBackEvent.


I found some Answer in stackoverflow but i can't solve this problem.

Camera onPreviewFrame not called

PreviewCallback and PreviewCallback with buffer are not called

Android Camera PreviewCallback not called in 4.1


Anyone help?


here is my Code

@Override
public void startPreview(String cameraId, int width, int height, int fps) {
    this.CameraId = cameraId;
    this.Width = width;
    this.Height = height;
    this.Fps = fps * 1000;

    this.CameraId = Integer.parseInt(cameraId);

    prepareCamera();

    if (this.RenderMethod == MyProject.RENDER_METHOD_NATIVE_SURFACE_TEXTURE) {
        MySurfaceRenderer.setSize(this.width, this.height);
    }

    startBackgroundThread();
    openCamera();
}

and This is my Callback Method :

private Camera.PreviewCallback myCallBack = new Camera.PreviewCallback() {
    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {
        Log.i(TAG, "onPreviewFrame data=" + data);

        JNIs.setFrameData(data);
        camera.addCallbackBuffer(this.PreviewData);
    }
};

and this is my openCamera Method :

private void openCamera() {
    if (this.Camera == null) {
        this.Camera = Camera.open(this.CameraId);
    }

    SurfaceTexture tex = MySurfaceRenderer.getSurfaceTexture();
    if (tex != null) {
        try {
            this.Camera.setPreviewTexture(tex);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    this.Data = new byte[this.width * this.height * 12 / 8];

    this.Params = this.Camera.getParameters();
    this.Params.setPreviewSize(this.width, this.height);

    // focus
    set_Focus(this.Params);

    // exposure
    set_Exposure(this.Params);

    this.Camera.setParameters(this.Params);
    this.Camera.setPreviewCallbackWithBuffer(myCallBack);
    this.Camera.startPreview();
    this.Camera.addCallbackBuffer(this.PreviewData);
}
0

There are 0 best solutions below