CameraView black on when being used for second time

ساخت وبلاگ

Vote count: 0

I am using CameraView library for showing a viewfinder and taking snaps from it. I have a button for opening the view and another button for closing the view.

Both the buttons click call the following method with true and false parameters:

public void showCameraLayout(boolean show) { cameraLoading.setVisibility(View.GONE); cameraClick.setVisibility(View.VISIBLE); ivGallery.setVisibility(View.VISIBLE); if (show) { showKeyboard(false); if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) { if (mCameraView != null) { mCameraView.addCallback(mCallback); } ViewGroup.LayoutParams params = cameraLayout.getLayoutParams(); params.height = messagesView.getWidth() / 2; cameraLayout.setLayoutParams(params); mCameraView.start(); safeToTakePicture = true; } else if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.CAMERA)) { ConfirmationDialogFragment .newInstance(R.string.camera_permission_confirmation, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION, R.string.camera_permission_not_granted) .show(getActivity().getSupportFragmentManager(), FRAGMENT_DIALOG); } else { ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION); } } else { ViewGroup.LayoutParams params = cameraLayout.getLayoutParams(); params.height = 0; cameraLayout.setLayoutParams(params); if (mCameraView != null) mCameraView.stop(); }
}

The problem is that when the cameraLayout is opened for the first time I can see the live camera. But if closed and opened again, it shows black screen. Weird thing is, I get a proper image if a snap is taken while black screen is being shown.

asked 43 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 299 تاريخ : دوشنبه 25 ارديبهشت 1396 ساعت: 12:32