Skip to content

Conversation

dhruv2295
Copy link
Contributor

No description provided.

@dhruv2295 dhruv2295 requested a review from thias15 September 16, 2021 11:09
@thias15
Copy link
Collaborator

thias15 commented Sep 20, 2021

Please fix the style.

@thias15 thias15 linked an issue Sep 20, 2021 that may be closed by this pull request
Copy link
Collaborator

@thias15 thias15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works. But on recording start there is shortly a black screen. Do you know why? Can this be fixed?

@hardikgarg02
Copy link
Contributor

hardikgarg02 commented Dec 28, 2023

Hi! I've fixed the issue related to the front-facing camera not opening in the fragment, which was causing video capturing to fail. Additionally, after shifting to a different fragment, the camera displays a blank screen.

Navigate to the CameraFragment.java file and replace the bindCameraUseCases function with the following code:

     protected void bindCameraUseCases() {
        converter = new YuvToRgbConverter(requireContext());
        bitmapBuffer = null;
        preview = new Preview.Builder().setTargetAspectRatio(AspectRatio.RATIO_16_9).build();
        final boolean rotated = ImageUtils.getScreenOrientation(requireActivity()) % 180 == 90;
        final PreviewView.ScaleType scaleType =
                rotated ? PreviewView.ScaleType.FIT_CENTER : PreviewView.ScaleType.FIT_START;
        previewView.setScaleType(scaleType);
        preview.setSurfaceProvider(previewView.getSurfaceProvider());
        CameraSelector cameraSelector =
                new CameraSelector.Builder().requireLensFacing(lensFacing).build();
        ImageAnalysis imageAnalysis;
        if (analyserResolution == null)
            imageAnalysis =
                    new ImageAnalysis.Builder().setTargetAspectRatio(AspectRatio.RATIO_16_9).build();
        else
            imageAnalysis = new ImageAnalysis.Builder().setTargetResolution(analyserResolution).build();

        imageAnalysis.setAnalyzer(
                cameraExecutor,
                image -> {
                    if (bitmapBuffer == null)
                        bitmapBuffer =
                                Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);

                    rotationDegrees = image.getImageInfo().getRotationDegrees();
                    converter.yuvToRgb(image.getImage(), bitmapBuffer);
                    image.close();

                    processFrame(bitmapBuffer, image);
                });
        try {
            if (cameraProvider != null) {
                cameraProvider.unbindAll();
                cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalysis);
            }
        } catch (Exception e) {
            Timber.e("Use case binding failed: %s", e.toString());
        }
        try {
            if (cameraProvider != null) {
                cameraProvider.unbindAll();
                cameraProvider.bindToLifecycle(this, cameraSelector, preview, videoCapture);
            }
        } catch (Exception e) {
            Timber.e("VideoCapture binding failed: %s", e.toString());
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logger Fragment - Video

3 participants