0 down vote favorite
So, I’ve been referencing this: http://developer.android.com/reference/android/hardware/Camera.html
I’m using LibGDX which is why you may see some difference, I’ve also changed mCamera to androidCamera for readability.
Here’s my code:
package com.fmeg.tapdat.android.camera;
import java.io.IOException;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import com.fmeg.tapdat.android.AndroidLauncher;
import com.fmeg.tapdat.camera.CameraInterface;
public class AndroidCamera extends SurfaceView implements
SurfaceHolder.Callback, CameraInterface {
private AndroidLauncher application;
private SurfaceHolder mHolder;
private Camera androidCamera;
public AndroidCamera(AndroidLauncher _application) {
super(_application.getContext());
this.application = _application;
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
surfaceCreated(mHolder);
}
@Override
public void showCamera(boolean show) {
androidCamera.startPreview();
}
/**
* Organized by call order
*/
@Override
public void surfaceCreated(SurfaceHolder holder) {
androidCamera = Camera.open();
try {
androidCamera.setPreviewDisplay(mHolder);
} catch (Exception e) {
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
Camera.Parameters params = androidCamera.getParameters();
params.setPreviewSize(width, height);
androidCamera.setParameters(params);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
androidCamera.stopPreview();
androidCamera = null;
}
}
I have an interface called CameraInterface with the following code:
package com.fmeg.tapdat.camera;
public interface CameraInterface {
public void showCamera(boolean show);
}
In my main class (android project) my code looks like this
public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
AndroidCamera cam = new AndroidCamera(this);
initialize(new TapdatGame(cam), config);
}
}
and in my main class (Core project)
package com.fmeg.tapdat;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.fmeg.tapdat.camera.CameraInterface;
public class TapdatGame extends ApplicationAdapter {
private CameraInterface camera;
public TapdatGame(CameraInterface cameraInterface) {
this.camera = cameraInterface;
}
@Override
public void create () {
camera.showCamera(true);
}
@Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
public CameraInterface getCamera() {
return camera;
}
}
Please help me get this working, the current implementation invokes an camera related error
[Camera]: Error 1001