Skip to main content
Version: Android SDK v1.1.0

Components

We provide three base Editor implementations that you can choose from depending on your case. Using them is a bit different but they all share the same functionality from the Editor interface.

EditorController

A EditorController is the low level implementation that, unlike the others, is detached from the UI. You will typically hold the controller instance in a ViewModel. Optionally, for perfect state restoration during configuration changes, we also recommend that you use Android's SavedStateHandle and pass it to the controller constructor.

class EditViewModel(state: SavedStateHandle) : ViewModel() {

val editor = EditorController(state)

override fun onCleared() {
super.onCleared()
editor.release()
}
}

As you can see, the EditorController must be released when you're done with it. In order to show the UI (e.g. video preview), you must also call one of the bind methods as soon as you have a view container. For example, with a fragment:

class EditFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.editor.bind(this, view.findViewById(R.id.container))
}

// Necessary if you use importSegments()
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
viewModel.editor.onActivityResult(requestCode, resultCode, data)
}
}

By passing in the fragment instance, the controller will use the fragment lifecycle to avoid memory leaks, so that there's no need to unbind.

EditorFragment

The EditorFragment is a fragment implemented exactly as described above. It is the recommended implementation as it is very easy to use - no need to release or bind UI, because the fragment owns the views.

You can customize the fragment after it is attached or when creating it, thanks to the EditorOptions class:

val options = EditorOptions.build {
overlay(R.layout.custom_controls)
saveToGallery(true)
loop(true)
mute(false)
}
val editor = EditorFragment.newInstance(options)

EditorView

The EditorView is a view that holds a controller, to be used for codebases that do not use fragments at all. Just like the controller, you must pass a fragment / activity / lifecycle with bind() to use it.

class EditActivity : AppCompatActivity() {

val editor by lazy { findViewById<EditorView>(R.id.editor) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.editor_view)
editor.bind(this) // necessary!
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
editor.onActivityResult(requestCode, resultCode, data)
}
}