Reputation: 1645
public static Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
if (c != null) {
Camera.Parameters params = c.getParameters();
params.setRotation(90);
c.setParameters(params);
}
} catch (Exception e) {
Log.d("DEBUG", "Camera did not open");
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
onCreate:
// Create an instance of Camera
mCamera = getCameraInstance();
mPreview = new CameraPreview(this, mCamera);
preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
CameraPreview:
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
I using MediaRecorder record video. Result: if i test on device android 4.0, result is ok. but in android 2.3 it is interference Why video of camera interference in android 2.3?(Note: Capture Image , it is ok.)
Upvotes: 0
Views: 157
Reputation: 13223
This is just one potential problem. From the docs:
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
You are not implementing the Camera API correctly. Please look at the Android Guide on how to create a camera app.
Upvotes: 1