Android Jetpack CameraX method createSurfaceProvider() not found

Tags: , ,



I ran into a problem when working with CameraX on the tutorial from the android documentation not to find a method createSurfaceProvider()

i am using these libraries: camerax_version = "1.0.0-beta10"

CODE:

@Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        previewView = view.findViewById(R.id.previewView);

        ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
                ProcessCameraProvider.getInstance(requireContext());

        cameraProviderFuture.addListener(() -> {
            try {
                ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
                bindPreview(cameraProvider);

            } catch (InterruptedException | ExecutionException e) {

            }
        }, ContextCompat.getMainExecutor(requireContext()));
    }

    private void bindPreview(ProcessCameraProvider cameraProvider) {
        Preview preview = new Preview.Builder().build();

        imageCapture = new ImageCapture.Builder()
                .setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
                .build();

        CameraSelector cameraSelector = new CameraSelector.Builder()
                .requireLensFacing(CameraSelector.LENS_FACING_BACK)
                .build();

        Camera camera = cameraProvider.bindToLifecycle(
                ((LifecycleOwner) this),
                cameraSelector,
                preview,
                imageCapture);

        preview.setSurfaceProvider(
                previewView.createSurfaceProvider(camera.getCameraInfo()));
            
                            ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
    }

Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details. Forgive me please, this text is needed not to swear at what I am quoting: It looks like your post is mostly code; please add some more details.

Answer

Just followed the latest tutorial and faced with same issue. But if you simply call the property surfaceProvider of your preview everything will work.

val preview = Preview.Builder() .build() .also { it.setSurfaceProvider(viewFinder.surfaceProvider) }



Source: stackoverflow