# Recording

Artifact: [androidx.camera:camera-video](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/video/Recording.java+class:androidx.camera.video.Recording) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
public final class Recording implements AutoCloseable
```

<br />

*** ** * ** ***

Provides controls for the currently active recording.

An active recording is created by starting a pending recording with `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)`. If there are no errors starting the recording, upon creation, an active recording will provide controls to pause, resume or stop a recording. If errors occur while starting the recording, the active recording will be instantiated in a `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize` state, and all controls will be no-ops. The state of the recording can be observed by the video record event listener provided to `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)` when starting the recording.

Either `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` or `https://developer.android.com/reference/androidx/camera/video/Recording#close()` can be called when it is desired to stop the recording. If `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` or `https://developer.android.com/reference/androidx/camera/video/Recording#close()` are not called on this object before it is no longer referenced, it will be automatically stopped at a future point in time when the object is garbage collected, and no new recordings can be started from the same `https://developer.android.com/reference/androidx/camera/video/Recorder` that generated the object until that occurs.

## Summary

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#close()()` Close this recording. |
| `boolean` | `@https://developer.android.com/reference/androidx/camera/video/ExperimentalPersistentRecording https://developer.android.com/reference/androidx/camera/video/Recording#isPersistent()()` Returns whether this recording is a persistent recording. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#mute(boolean)(boolean muted)` Mutes or un-mutes the current recording. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#pause()()` Pauses the current recording if active. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#resume()()` Resumes the current recording if paused. |
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#stop()()` Stops the recording, as if calling `https://developer.android.com/reference/androidx/camera/video/Recording#close()`. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/camera/video/Recording#finalize()()` |

## Public methods

### close

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public void close()
```

Close this recording.

Once `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` or `close()` called, all methods for controlling the state of this recording besides `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` or `close()` will throw an `https://developer.android.com/reference/java/lang/IllegalStateException.html`.

Once an active recording has been closed, the next recording can be started with `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)`.

This method is idempotent; if the recording has already been closed or has been finalized internally, calling `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` or `close()` is a no-op.

This method is invoked automatically on active recording instances managed by the `
try-with-resources` statement.

### isPersistent

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
@ExperimentalPersistentRecording
public boolean isPersistent()
```

Returns whether this recording is a persistent recording.

A persistent recording will only be stopped by explicitly calling of `https://developer.android.com/reference/androidx/camera/video/Recording#stop()` and will ignore the lifecycle events or source state changes. Users are responsible of stopping a persistent recording.

| Returns |
|---|---|
| `boolean` | `true` if the recording is a persistent recording, otherwise `false`. |

### mute

Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public void mute(boolean muted)
```

Mutes or un-mutes the current recording.

The output file will contain an audio track even the whole recording is muted. Create a recording without calling `https://developer.android.com/reference/androidx/camera/video/PendingRecording#withAudioEnabled()` to record a file with no audio track. To set the initial mute state of the recording, use `https://developer.android.com/reference/androidx/camera/video/PendingRecording#withAudioEnabled(boolean)`.

Muting or unmuting a recording that isn't created `https://developer.android.com/reference/androidx/camera/video/PendingRecording#withAudioEnabled()` with audio enabled is no-op.

| Parameters |
|---|---|
| `boolean muted` | mutes the recording if `true`, un-mutes otherwise. |

### pause

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public void pause()
```

Pauses the current recording if active.

Successful pausing of a recording will generate a `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Pause` event which will be sent to the listener passed to `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)`.

If the recording has already been paused or has been finalized internally, this is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the recording has been stopped with `https://developer.android.com/reference/androidx/camera/video/Recording#close()` or `https://developer.android.com/reference/androidx/camera/video/Recording#stop()`. |

### resume

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public void resume()
```

Resumes the current recording if paused.

Successful resuming of a recording will generate a `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Resume` event which will be sent to the listener passed to `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)`.

If the recording is active or has been finalized internally, this is a no-op.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | if the recording has been stopped with `https://developer.android.com/reference/androidx/camera/video/Recording#close()` or `https://developer.android.com/reference/androidx/camera/video/Recording#stop()`. |

### stop

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

```
public void stop()
```

Stops the recording, as if calling `https://developer.android.com/reference/androidx/camera/video/Recording#close()`.

This method is equivalent to calling `https://developer.android.com/reference/androidx/camera/video/Recording#close()`.

## Protected methods

### finalize

```
protected void finalize()
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable.html` |   |