VideoRecordEvent


public 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

public final class VideoRecordEvent.Finalize extends VideoRecordEvent

Indicates the finalization of recording.

public final class VideoRecordEvent.Pause extends VideoRecordEvent

Indicates the pause event of recording.

public final class VideoRecordEvent.Resume extends VideoRecordEvent

Indicates the resume event of recording.

public final class VideoRecordEvent.Start extends VideoRecordEvent

Indicates the start of recording.

public final class VideoRecordEvent.Status extends VideoRecordEvent

The status report of the recording in progress.

Public methods

@NonNull OutputOptions

Gets the OutputOptions associated with this event.

@NonNull RecordingStats

Gets the recording statistics of current event.

Public methods

getOutputOptions

Added in 1.1.0
public @NonNull OutputOptions getOutputOptions()

Gets the OutputOptions associated with this event.

getRecordingStats

Added in 1.1.0
public @NonNull RecordingStats getRecordingStats()

Gets the recording statistics of current event.