Skip to main content
Version: 1.2.0

State & Events

Every io.video.videokit.editor.Editor implementation keeps its internal state and offers a way to register listener objects to listen to important events.

Editor state#

The editor state can be retrieved with editor.state and, similar to other VideoKit components, matches one of the constants in the io.video.videokit.editor.EditorState class:

StateDescription
EditorState.PREVIEWEditor is in preview mode. This means that no segment was selected and video playback, if used, will play all segments serially.
EditorState.EDITINGA segment was selected using editor.selectSegment(), so video playback, if used, will play the selected segment only.
EditorState.FINALIZINGeditor.confirm() was called and the editor is busy transcoding all segments to create a single file. Use editor.progress to keep track of the progress and wait for onResult(Edit).

Editor events#

All Editor events are dispatched to a io.video.videokit.editor.EditorListener that was previously registered using addListener.

editor.addListener(lifecycle, listener) // start listening, stops automatically
editor.addListener(listener) // start listening
editor.removeListener(listener) // stop listening

Listeners are very important to be up-to-date about the editor state, handle errors and create a responsive UI. We describe the listener interface as comments in the interface description below.

editor.addListener(object : EditorListener {
override fun onResult(edit: Edit) {
// Called after confirming the edit and transcoding segments.
// The edit object contains the merged video uri.
}
override fun onError(error: VideoError) {
// Something went wrong! Handle the error.
}
override fun onStateChanged(@EditorState.Value state: Int) {
// State changed!
}
override fun onSegmentsChanged(segments: List<Segment>) {
// Contains the list of segments carrying information about them.
// Called anytime any of them changes or is added or is removed.
}
override fun onSelectedSegmentChanged(segment: Segment?) {
// Called in response of selectSegment / unselectSegment calls.
}
override fun onDurationChanged(duration: Long) {
// The playback duration has changed. This can happen, for instance, when one of the
// videos is trimmed using trimSegment(), or when segments are added or removed.
// When a segment is selected, the duration is set to that segment duration.
}
override fun onPositionChanged(position: Long) {
// The playback position has changed. This is invoked many times during
// playback to implement a smooth UI seekbar, for example.
// Value goes from 0 up to editor.duration.
}
override fun onProgress(progress: Double) {
// Editor is in FINALIZING state and making progress on the transcoding process.
// The progress double goes from 0.0 to 1.0.
}
override fun onPlayChanged(playing: Boolean) {
// Reports changes in the editor.playing boolean, which changes when playback
// APIs like play/pause/toggle are used.
}
})
Last updated on