# Media3Effect

Artifact: [androidx.camera.media3:media3-effect](https://developer.android.com/jetpack/androidx/releases/camera-media3) [View Source](https://cs.android.com/search?q=file:androidx/camera/media3/effect/Media3Effect.kt+class:androidx.camera.media3.effect.Media3Effect) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/camera-media3#1.0.0-alpha04)

*** ** * ** ***


```
public final class Media3Effect extends CameraEffect implements AutoCloseable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.camera.core.CameraEffect](https://developer.android.com/reference/androidx/camera/core/CameraEffect) ||
|   | ↳ | [androidx.camera.media3.effect.Media3Effect](https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect) |

*** ** * ** ***

A CameraEffect that applies media3 `https://developer.android.com/reference/androidx/media3/common/Effect` to the CameraX pipeline

This class is an adapter between the CameraX `https://developer.android.com/reference/androidx/camera/core/CameraEffect` API and the media3 `https://developer.android.com/reference/androidx/media3/common/Effect` API. It allows the media3 `https://developer.android.com/reference/androidx/media3/common/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 |
|---|
| `https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect#Media3Effect(android.content.Context,kotlin.Int,java.util.concurrent.Executor,androidx.core.util.Consumer)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, int targets, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html> errorListener )` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect#close()()` Closes the `https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect` and releases all the resources. |
| `final void` | `https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect#setEffects(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/media3/common/Effect> effects)` Applies a list of media3 effects to the camera output. |

| ### Inherited methods |
|---|
| From [androidx.camera.core.CameraEffect](https://developer.android.com/reference/androidx/camera/core/CameraEffect) |---|---| | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html>` | `https://developer.android.com/reference/androidx/camera/core/CameraEffect#getErrorListener()()` | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/androidx/camera/core/CameraEffect#getExecutor()()` | | `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/camera/core/SurfaceProcessor` | `https://developer.android.com/reference/androidx/camera/core/CameraEffect#getSurfaceProcessor()()` | | `int` | `https://developer.android.com/reference/androidx/camera/core/CameraEffect#getTargets()()` | |

## Public constructors

### Media3Effect

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/camera-media3#1.0.0-alpha04)

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the Android context |
| `int targets` | the target UseCase to which this effect should be applied. For details, see `https://developer.android.com/reference/androidx/camera/core/CameraEffect`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the errorListener will be invoked. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html> errorListener` | invoked if the effect runs into unrecoverable errors. The `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` will be the error thrown by this `https://developer.android.com/reference/androidx/camera/media3/effect/Media3Effect`. This is invoked on the provided executor. |

## Public methods

### close

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/camera-media3#1.0.0-alpha04)

```
public void close()
```

Closes the `https://developer.android.com/reference/androidx/camera/media3/effect/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.