VideoRecordEvent

public abstract class VideoRecordEvent
extends Object

java.lang.Object
   ↳ androidx.camera.video.VideoRecordEvent


VideoRecordEvent is used to report video recording events and status.

Upon starting a recording by PendingRecording.start(Executor, Consumer), recording events will start to be sent to the listener passed to PendingRecording.start(Executor, Consumer).

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

The VideoRecordEvent.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 classes

class VideoRecordEvent.Finalize

Indicates the finalization of recording. 

class VideoRecordEvent.Pause

Indicates the pause event of recording. 

class VideoRecordEvent.Resume

Indicates the resume event of recording. 

class VideoRecordEvent.Start

Indicates the start of recording. 

class VideoRecordEvent.Status

The status report of the recording in progress. 

Public methods

OutputOptions getOutputOptions()

Gets the OutputOptions associated with this event.

RecordingStats getRecordingStats()

Gets the recording statistics of current event.

Inherited methods

Public methods

getOutputOptions

public OutputOptions getOutputOptions ()

Gets the OutputOptions associated with this event.

Returns
OutputOptions

getRecordingStats

public RecordingStats getRecordingStats ()

Gets the recording statistics of current event.

Returns
RecordingStats