an error occurred by CameraX.bindToLifecycle()
Asked Answered
R

6

16

java.lang.IllegalArgumentException: No supported surface combination is found for camera device - Id : 0. May be attempting to bind too many use cases.

why the bindToLifecycle() only choose imageCapture or videoCapture?

 CameraX.bindToLifecycle(lifecycleOwner, mPreview, imageCapture,videoCapture)
Rowney answered 20/7, 2019 at 16:9 Comment(1)
Did you manage to fix this issue or maybe did you figure out a workaround? I'm having the exact same issue.Rout
S
6

You are binding more UseCases than your device's camera supports. Not all devices can support two ImageAnalyzers.

Try reducing your analyzers,

CameraX.bindToLifecycle(lifecycleOwner, mPreview, imageCapture or videoCapture)

I have tested with many devices, so far, among the devices that I tested, only Google Pixel 1 works with three analyzers.

To suggest a hack, remove imageCapture analyzer, try to get images from preview for imageCapture and use videoCapture.

Hope it helps.

Spay answered 25/7, 2019 at 5:52 Comment(0)
W
6

I got the same error while popping fragment with camera view from backstack, I fixed it by unbinding all analysers when view exits.

CameraX.unbindAll()

As suggested here.

Wavelength answered 3/10, 2019 at 7:44 Comment(1)
This works but it refreshes the screen. How to avoid that ?Bogy
P
5

A workaround is to bind Preview with VideoCapture, and Preview with ImageCapture separately. Binding Preview, ImageCapture and VideoCapture appears to be an issue on a few devices currently. When switching between the two be careful to unbindAll first.

This may be because the VideoCapture UseCase is not officially supported yet, as of 1.0.0-Beta10.

fun startVideoCapture() {
        ...
                cameraProvider.unbindAll()
                cameraProvider.bindToLifecycle(
                                lifecycleOwner,
                                cameraSelected,
                                previewUseCase,
                                videoCaptureUseCase
                            )
                }
fun startImageCapture() {
        ...
                cameraProvider.unbindAll()
                cameraProvider.bindToLifecycle(
                                lifecycleOwner,
                                cameraSelected,
                                previewUseCase,
                                imageCaptureUseCase
                            )
                }
Pepperandsalt answered 23/10, 2020 at 16:45 Comment(0)
I
2

There is no videoCapture usecase right now.

As mentioned in the official documentation, the available usecases are preview, analysis & image capture (and their combinations).

Isomerism answered 20/7, 2019 at 16:14 Comment(0)
W
2

I got the same error when I tried to create imageCapture, videoCapture, mPreview or the analyzer with different settings between each other.

Try to set in the builder setting the same parameters, e.g. if you want:

setLensFacing(CameraX.LensFacing.BACK)

Set in all the setting builders the same. This can fix your error but still, I don't know if the library support this feature jet.

Warnke answered 4/8, 2019 at 11:22 Comment(1)
ImageCaptureConfig imgCConfig = new ImageCaptureConfig.Builder().setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY) .setTargetRotation(getWindowManager().getDefaultDisplay().getRotation()).setLensFacing( CameraX.LensFacing.BACK).build();Tablecloth
M
0

As Ye Min Htut pointed out, consider fewer UseCases. For me this was sufficient:

CameraX.bindToLifecycle(viewLifecycleOwner, cameraSelector)

I hope it can help someone out there =)

Mamiemamma answered 31/7, 2021 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.