public final class Media3Effect extends CameraEffect implements AutoCloseable


A CameraEffect that applies media3 Effect to the CameraX pipeline

This class is an adapter between the CameraX CameraEffect API and the media3 Effect API. It allows the media3 Effect to be applied to the CameraX pipeline on the fly without restarting the camera.

Code sample:

media3Effect = Media3Effect(requireContext(), PREVIEW or VIDEO_CAPTURE, executor) {
Log.e(TAG, "Error in Media3Effect: $it")
}

media3Effect.setEffects(listOf(Brightness(1.5f)))
cameraController.setEffects(setOf(media3Effect))

Summary

Public constructors

Media3Effect(
    @NonNull Context context,
    int targets,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull Throwable> errorListener
)

Public methods

void

Closes the Media3Effect and releases all the resources.

final void

Applies a list of media3 effects to the camera output.

Inherited methods

From androidx.camera.core.CameraEffect
@NonNull Consumer<@NonNull Throwable>

Gets the Error listener associated with this effect.

@NonNull Executor

Gets the Executor associated with this effect.

@Nullable SurfaceProcessor

Gets the SurfaceProcessor associated with this effect.

int

Ges the target UseCases of this effect.

Public constructors

Media3Effect

Added in 1.0.0-alpha01
public Media3Effect(
    @NonNull Context context,
    int targets,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull Throwable> errorListener
)
Parameters
@NonNull Context context

the Android context

int targets

the target UseCase to which this effect should be applied. For details, see CameraEffect.

@NonNull Executor executor

the Executor on which the errorListener will be invoked.

@NonNull Consumer<@NonNull Throwable> errorListener

invoked if the effect runs into unrecoverable errors. The Throwable will be the error thrown by this Media3Effect. This is invoked on the provided executor.

Public methods

close

Added in 1.0.0-alpha01
public void close()

Closes the Media3Effect and releases all the resources.

The caller should only close when the effect when it's no longer in use. Once closed, the effect should not be used again.

setEffects

public final void setEffects(@NonNull List<@NonNull Effect> effects)

Applies a list of media3 effects to the camera output.

Once set, the effects will be effective immediately. To clear the effect, call this method again with a empty list.