Unable to use Media3Effect in Preview or Video_Capture when using multiple camera configs

48 views
Skip to first unread message
Assigned to scot...@google.com by me

Sebastine “Hendrick” Odeh

unread,
Jun 15, 2025, 8:15:06 AMJun 15
to Android CameraX Discussion Group
The Camera crashes with the error below whenever I try to apply a Media3Effect in PREVIEW or VIDEO_CAPTURE mode. Applying the effect to either mode works, but using it together kills the Camera.
Screenshot 2025-06-15 at 13.11.42.png

And here's my code to bind the camera

suspend fun bindToCamera(applicationContext: Context, lifecycleOwner: LifecycleOwner) {
currentCameraProvider?.unbindAll()
currentCameraProvider = ProcessCameraProvider.awaitInstance(applicationContext)

var primaryCameraSelector: CameraSelector? = null
var secondaryCameraSelector: CameraSelector? = null

for (cameraInfos in currentCameraProvider!!.availableConcurrentCameraInfos) {
primaryCameraSelector =
cameraInfos.firstOrNull { it.lensFacing == CameraSelector.LENS_FACING_BACK }?.cameraSelector
secondaryCameraSelector =
cameraInfos.firstOrNull { it.lensFacing == CameraSelector.LENS_FACING_FRONT }?.cameraSelector
if (primaryCameraSelector != null && secondaryCameraSelector != null) {
break // Found both, stop searching
} else {
primaryCameraSelector = null
secondaryCameraSelector = null
}
}

if (primaryCameraSelector == null || secondaryCameraSelector == null) return

val effect = Media3Effect(
applicationContext,
PREVIEW or VIDEO_CAPTURE,
applicationContext.mainExecutor
) {
Log.e("DualCameraSingleVideoUseCase", "Applying media3effect failed with", it)
}

val resolutionSelector = ResolutionSelector.Builder().setAspectRatioStrategy(
AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY
).build()
val preview = Preview.Builder().setResolutionSelector(resolutionSelector).build()


preview.setSurfaceProvider { newSurfaceRequest ->
_mSurfaceRequest.update { newSurfaceRequest }
}

val recorder = Recorder.Builder().setQualitySelector(
QualitySelector.from(Quality.HD)
).build()
videoCapture = VideoCapture.withOutput(recorder)

effect.setEffects(listOf(Contrast(0.5f)))

val useCaseGroup = UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(videoCapture!!)
.addEffect(effect)
.build()

val primary = SingleCameraConfig(
primaryCameraSelector,
useCaseGroup,
CompositionSettings.Builder()
.setAlpha(1.0f)
.setOffset(0.0f, 0.0f)
.setScale(1.0f, 1.0f)
.build(),
lifecycleOwner
)
val secondary = SingleCameraConfig(
secondaryCameraSelector,
useCaseGroup,
CompositionSettings.Builder()
.setAlpha(1.0f)
.setOffset(0.65f, -0.7f)
.setScale(0.25f, 0.25f)
.build(),
lifecycleOwner
)

currentCameraProvider?.bindToLifecycle(listOf(primary, secondary))

try {
awaitCancellation()
} finally {
currentCameraProvider!!.unbindAll()
}
}

Sebastine “Hendrick” Odeh

unread,
Jun 15, 2025, 10:27:30 AMJun 15
to Android CameraX Discussion Group, Sebastine Odeh
Creating two Media3Effect instances, one for preview and the other for video_capture, works as a hack for this issue. Unfortunately, I'm unable to combine them at the moment. I'm using version 1.5.0-beta01 of camera-compose, and its libraries

Scott Nien

unread,
Jun 17, 2025, 4:00:45 AMJun 17
to Sebastine “Hendrick” Odeh, Android CameraX Discussion Group
This is indeed an issue. 
I've filed a bug 

We will try to fix it in Q3. 
Scott

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/19fbadcf-f03e-4b66-832e-3b6321ff473en%40android.com.
Reply all
Reply to author
Forward
0 new messages