3

I'm continuously getting this error.when i try to open up camera using CameraX library. same code runs on other device less than pie. but not running on pie(Camera is not showing)

Here is my code: and I'm also using life data in my project can it cause any issue ?

  val previewConfig = PreviewConfig.Builder()
            .setLensFacing(CameraX.LensFacing.BACK)
            .build()
    val preview = Preview(previewConfig)
    preview.setOnPreviewOutputUpdateListener { previewOutput ->
        _textureView.surfaceTexture = previewOutput.surfaceTexture
    }
    val imageAnalysisConfig = ImageAnalysisConfig.Builder()
        .build()
    val imageAnalysis = ImageAnalysis(imageAnalysisConfig)
    val qrCodeAnalyzer = QRCodeAnalyzer { qrCodes ->
        qrCodes.forEach {
            Log.d("MainActivity", "QR Code detected: `${it.rawValue}.")`
            val intent = intent.putExtra("RESULT",it.rawValue)
            setResult(Activity.RESULT_OK,intent)
            finish()
        }
    }

    imageAnalysis.analyzer = qrCodeAnalyzer

    // We need to bind preview and imageAnalysis use cases
    CameraX.bindToLifecycle(this as LifecycleOwner , preview, imageAnalysis)

Logs: Check out the logs I'm getting

 E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
E/GLConsumer: [SurfaceTexture-0-3196-1] updateAndRelease: GLConsumer is not attached to an OpenGL ES context
eisbehr
  • 12,243
  • 7
  • 38
  • 63

1 Answers1

4

I just had similar issue. I solve it by removing and re-adding SurfaceTexture as suggested here https://stackoverflow.com/a/56121351/11977949.

You should change setOnPreviewOutputUpdateListener to:

preview.setOnPreviewOutputUpdateListener {
    val parent = viewFinder.parent as ViewGroup
    parent.removeView(viewFinder)
    viewFinder.surfaceTexture = it.surfaceTexture
    parent.addView(viewFinder, 0)
    updateTransform()
}

For more details, check official sample.

Danijel
  • 111
  • 4