Skip to main content
Language:

Force Trim - Fixed Length Video

If you configured the TrimSettings to restrict the duration of the video by setting a minimum and/or maximum duration you can define the startup behavior of the video editor as follows:

  • The composition or trim tool will always automatically be presented after opening for the user to review and adjust the length of the video. This corresponds to setting forceTrimMode to ALWAYS.
  • forceTrimMode is set to IF_NEEDED as in our example and will only present
    • the composition tool, if your initial composition is longer than maximumVideoLength or shorter than minimumVideoLength, or
    • the trim tool, if your initial video is longer than maximumVideoLength.
  • Setting forceTrimMode to SILENT will automatically trim the video to the maximumVideoLength without opening any tool and is the default behavior.
File:
class TrimEnforceDuration(private val activity: AppCompatActivity) : Example(activity) {
override fun invoke() {
// In this example, we do not need access to the Uri(s) after the editor is closed
// so we pass false in the constructor
val settingsList = VideoEditorSettingsList(false)
// Set the source as the Uri of the video to be loaded
.configure<LoadSettings> {
it.source = activity.resourceUri(R.raw.skater)
}
// The min/max length limits are also respected by the VideoCompositionToolPanel.
settingsList.configure<TrimSettings> {
// By default the editor does not allow videos shorter than 0.5 seconds. For this example the duration is set,
// e.g. for a social media application where the posts are not allowed to be shorter than 2 seconds.
// highlight-min-max
it.setMinimumVideoLength(2, TimeUnit.SECONDS)
// By default the editor does not have a maximum duration. For this example the duration is set,
// e.g. for a social media application where the posts are not allowed to be longer than 5 seconds.
it.setMaximumVideoLength(5, TimeUnit.SECONDS)
// highlight-min-max
// By default the editor trims the video automatically if it is longer than the specified maximum duration.
// For this example, the user is prompted to review and adjust the automatically trimmed video.
it.forceTrimMode = TrimSettings.ForceTrim.IF_NEEDED
}
// Start the video editor using VideoEditorBuilder
// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODE
VideoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
// Release the SettingsList once done
settingsList.release()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
intent ?: return
if (requestCode == EDITOR_REQUEST_CODE) {
// Wrap the intent into an EditorSDKResult
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
}
}