# VideoRecordEvent

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/VideoRecordEvent.java+class:androidx.camera.video.VideoRecordEvent) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***


```
public abstract class VideoRecordEvent
```

<br />

Known direct subclasses [VideoRecordEvent.Finalize](https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize), [VideoRecordEvent.Pause](https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Pause), [VideoRecordEvent.Resume](https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Resume), [VideoRecordEvent.Start](https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start), [VideoRecordEvent.Status](https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Status)

|---|---|
| `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize` | Indicates the finalization of recording. |
| `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Pause` | Indicates the pause event of recording. |
| `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Resume` | Indicates the resume event of recording. |
| `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start` | Indicates the start of recording. |
| `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Status` | The status report of the recording in progress. |

*** ** * ** ***

VideoRecordEvent is used to report video recording events and status.

Upon starting a recording by `https://developer.android.com/reference/androidx/camera/video/PendingRecording#start(java.util.concurrent.Executor,androidx.core.util.Consumer<androidx.camera.video.VideoRecordEvent>)`, recording events will start to 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>)`.

There are `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start`, `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize`, `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Status`, `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Pause` and `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Resume` events.

Example: Below is the typical way to determine the event type and cast to the event class, if needed.

```
Recording recording = recorder.prepareRecording(context, outputOptions)
    .start(ContextCompat.getMainExecutor(context), videoRecordEvent -> {
        if (videoRecordEvent instanceof VideoRecordEvent.Start) {
            // Handle the start of a new active recording
            ...
        } else if (videoRecordEvent instanceof VideoRecordEvent.Pause) {
            // Handle the case where the active recording is paused
            ...
        } else if (videoRecordEvent instanceof VideoRecordEvent.Resume) {
            // Handles the case where the active recording is resumed
            ...
        } else if (videoRecordEvent instanceof VideoRecordEvent.Finalize) {
            VideoRecordEvent.Finalize finalizeEvent =
                (VideoRecordEvent.Finalize) videoRecordEvent;
            // Handles a finalize event for the active recording, checking Finalize.getError()
            int error = finalizeEvent.getError();
            if (error != Finalize.ERROR_NONE) {
                ...
            }
        }

        // All events, including VideoRecordEvent.Status, contain RecordingStats.
        // This can be used to update the UI or track the recording duration.
        RecordingStats recordingStats = videoRecordEvent.getRecordingStats();
        ...
    });
```

If using Kotlin, the VideoRecordEvent class can be treated similar to a `sealed
class`. In Kotlin, it is recommended to use a `when` expression rather than an `
if`-`else if` chain as in the above example.

When a video recording is requested, `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start` event will be reported at first and `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize` event will be reported when the recording is finished. The stop reason can be obtained via `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#getError()`. `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#ERROR_NONE()` means that the video was recorded successfully, and other error code indicate the recording is failed or stopped due to a certain reason. Please note that a failed result does not mean that the video file has not been generated. In some cases, the file can still be successfully generated. For example, the result `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#ERROR_FILE_SIZE_LIMIT_REACHED()` will still have video file.

The `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Status` event will be triggered continuously during the recording process, `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent#getRecordingStats()` can be used to get the recording state such as total recorded bytes and total duration when the event is triggered.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize extends https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent` Indicates the finalization of recording. |
| `public final class https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Pause extends https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent` Indicates the pause event of recording. |
| `public final class https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Resume extends https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent` Indicates the resume event of recording. |
| `public final class https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Start extends https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent` Indicates the start of recording. |
| `public final class https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Status extends https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent` The status report of the recording in progress. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/OutputOptions` | `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent#getOutputOptions()()` Gets the `https://developer.android.com/reference/androidx/camera/video/OutputOptions` associated with this event. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/video/RecordingStats` | `https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent#getRecordingStats()()` Gets the recording statistics of current event. |

## Public methods

### getOutputOptions

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

```
public @NonNull OutputOptions getOutputOptions()
```

Gets the `https://developer.android.com/reference/androidx/camera/video/OutputOptions` associated with this event.

### getRecordingStats

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

```
public @NonNull RecordingStats getRecordingStats()
```

Gets the recording statistics of current event.