i'm trying to develop an android camera app using camera2 API. the code works fine. however after testing it on nexus 5X the createCaptureSession always fail if i add multiple Surface and the onConfigureFailed method get called below is the code i'm using
any idea why this is happening only with nexus 5X
protected void startPreview() {
if (null == mCameraDevice) {
// Log.d(TAG, "mCameraDevice is null");
return;
}
//close Preview Session
if (mCaptureSession != null) {
mCaptureSession.close();
mCaptureSession = null;
}
try {
SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
Surface previewSurface = new Surface(texture);
mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewBuilder.addTarget(previewSurface);
//mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader), new CameraCaptureSession.StateCallback(){ this line fails
mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback(){ // this works
@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
mCaptureSession = cameraCaptureSession;
mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
updatePreview();
}
@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
Toast.makeText(this, "onConfigureFailed", Toast.LENGTH_SHORT).show();
}
}, null);
} catch (Exception e) {
Log.e(TAG, "startPreview faild",e);
e.printStackTrace();
}
}
Try adding some delay before
createCaptureSession()
.