VideoRecordEvent


abstract class VideoRecordEvent

Known direct subclasses
VideoRecordEvent.Finalize

Indicates the finalization of recording.

VideoRecordEvent.Pause

Indicates the pause event of recording.

VideoRecordEvent.Resume

Indicates the resume event of recording.

VideoRecordEvent.Start

Indicates the start of recording.

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 start, recording events will start to be sent to the listener passed to start.

There are Start, Finalize, Status, Pause and 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, Start event will be reported at first and Finalize event will be reported when the recording is finished. The stop reason can be obtained via getError. 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 ERROR_FILE_SIZE_LIMIT_REACHED will still have video file.

The Status event will be triggered continuously during the recording process, 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

Indicates the finalization of recording.

Indicates the pause event of recording.

Indicates the resume event of recording.

Indicates the start of recording.

The status report of the recording in progress.

Public functions

OutputOptions

Gets the OutputOptions associated with this event.

RecordingStats

Gets the recording statistics of current event.

Public functions

getOutputOptions

Added in 1.1.0
fun getOutputOptions(): OutputOptions

Gets the OutputOptions associated with this event.

getRecordingStats

Added in 1.1.0
fun getRecordingStats(): RecordingStats

Gets the recording statistics of current event.