question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CameraX Back and front camera can't preview at same time ?

See original GitHub issue
previewBack.setSurfaceProvider(viewBack.surfaceProvider)
previewFront.setSurfaceProvider(viewFront.surfaceProvider)
val cameraBack = cameraProvider.bindToLifecycle(this, cameraSelectorBack, previewBack)
val cameraFront = cameraProvider.bindToLifecycle(this, cameraSelectorFront, previewFront)
 java.lang.IllegalArgumentException: Multiple LifecycleCameras with use cases are registered to the same LifecycleOwner.
        at androidx.camera.lifecycle.LifecycleCameraRepository.bindToLifecycleCamera(LifecycleCameraRepository.java:269)
        at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:423)
        at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:274)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
taiyabalicommented, May 11, 2021

Hii guy’s use - cameraProvider.unbindAll() // Unbind use cases before rebinding,

btnSwitchCamera.setOnClickListener {

        if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA && cameraProvider.hasCamera(
                CameraSelector.DEFAULT_BACK_CAMERA)) {

            cameraProvider.unbindAll()    // Unbind use cases before rebinding

            cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
            val preview = Preview.Builder().build().also {
                it.setSurfaceProvider(viewFinder.createSurfaceProvider())
            }
            cameraProvider.bindToLifecycle(this, cameraSelector, preview)
            
        } else if (cameraSelector == CameraSelector.DEFAULT_BACK_CAMERA && cameraProvider.hasCamera(
                CameraSelector.DEFAULT_FRONT_CAMERA)) {

            cameraProvider.unbindAll()    // Unbind use cases before rebinding

            cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA
            val preview = Preview.Builder().build().also {
                it.setSurfaceProvider(viewFinder.createSurfaceProvider())
            }
            cameraProvider.bindToLifecycle(this, cameraSelector, preview)
        }

    }
0reactions
letuss004commented, Dec 29, 2021

@agent10 haha i expected an camerax but camera2 fair enough. Did u share source in github? I really want to take a look

Read more comments on GitHub >

github_iconTop Results From Across the Web

android camerax - Camera X - Accessing both Front and Back ...
Upon home press and launching app again, either one of the preview (Back or Front) shows up and there is no pattern found....
Read more >
Open Both Front And Back Cameras Simultaneously
You see, our devices have proximity sensors and when we detect a user's presence, we turn on the cameras and show the preview...
Read more >
Can We Use the Front & Back Cameras at the Same Time on ...
TL;DR: Yes, if the device's software and hardware support it, which can't be taken for granted. Currently, the only way how to query...
Read more >
CameraX preview only show black view on Samsun S8 ...
As the document states, LIMITED-level camera (front camera of S8) are not guaranteed to support MAXIMUM/YUV and other streams at the same time....
Read more >
How to Use the Front and Rear Camera Previews ...
Set Up Views for Preview​​ We will require two separate views to present the preview from two cameras. We will start small by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found