# 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)

*** ** * ** ***


```
class Media3Effect : CameraEffect, AutoCloseable
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.camera.core.CameraEffect](https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect) ||
|   | ↳ | [androidx.camera.media3.effect.Media3Effect](https://developer.android.com/reference/kotlin/androidx/camera/media3/effect/Media3Effect) |

*** ** * ** ***

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

This class is an adapter between the CameraX `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` API and the media3 `https://developer.android.com/reference/kotlin/androidx/media3/common/Effect` API. It allows the media3 `https://developer.android.com/reference/kotlin/androidx/media3/common/Effect` to be applied to the CameraX pipeline on the fly without restarting the camera.

Code sample:

```kotlin
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/kotlin/androidx/camera/media3/effect/Media3Effect#Media3Effect(android.content.Context,kotlin.Int,java.util.concurrent.Executor,androidx.core.util.Consumer)( context: https://developer.android.com/reference/android/content/Context.html, targets: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, errorListener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html> )` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/media3/effect/Media3Effect#close()()` Closes the `https://developer.android.com/reference/kotlin/androidx/camera/media3/effect/Media3Effect` and releases all the resources. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/media3/effect/Media3Effect#setEffects(kotlin.collections.List)(effects: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/media3/common/Effect>)` Applies a list of media3 effects to the camera output. |

| ### Inherited properties |
|---|
| From [androidx.camera.core.CameraEffect](https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect) |---|---| | `open https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html>` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect#errorListener()` | | `open https://developer.android.com/reference/java/util/concurrent/Executor.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect#executor()` | | `open https://developer.android.com/reference/kotlin/androidx/camera/core/SurfaceProcessor?` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect#surfaceProcessor()` | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect#targets()` | |

## Public constructors

### Media3Effect

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

```
Media3Effect(
    context: Context,
    targets: Int,
    executor: Executor,
    errorListener: Consumer<Throwable>
)
```

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | the Android context |
| `targets: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the target UseCase to which this effect should be applied. For details, see `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect`. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | the `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the errorListener will be invoked. |
| `errorListener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html>` | 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/kotlin/androidx/camera/media3/effect/Media3Effect`. This is invoked on the provided executor. |

## Public functions

### close

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

```
open fun close(): Unit
```

Closes the `https://developer.android.com/reference/kotlin/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

```
fun setEffects(effects: List<Effect>): Unit
```

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.