Skip to main content
Language:

Configure Trim

VideoEditor SDK supports configuring the VideoTrimToolPanel to enforce a minimum and maximum duration of the trimmed video.

Min / Max Duration#

By default, the minimum video duration enforced is 0.5 seconds and there is no limit on the maximum video duration. In this example, we only allow videos that are at least two seconds and at most five seconds long.

Behavior and user alerts for exceptions#

If enabled, the trim length will initially be set to the maximumVideoLength. If this value is not set, or the video length is shorter than the maximumVideoLength, it will be set to the full length of the video. The user interface will not allow a trim length that is shorter than minimumVideoLength or longer than maximumVideoLength, so users will never be able to generate a video that lies outside these defined limits. However, there are two cases where this behavior can only be achieved with an alert:

  1. If a minimumVideoLength has been set for the trim tool and the length of the input video is shorter than that, we will present an alert as soon as the editor is opened stating that the video is too short. After confirming that alert, the editor is closed.
  2. If a minimumVideoLength has been set for the composition tool and the length of the video composition does not yet overstep that length, tapping on the export button will present an alert that notifies the user that they will have to add additional videos to the composition to export the video. After confirming the alert, the composition tool will automatically open. If you do not allow your users to add additional videos to the composition when UiConfigComposition.allowAddVideoClips is set to false, the behavior will be identical as if the trim tool would have been used above.

Trim or Video Composition tool#

The video composition tool will only be used if it is included in your subscription and if it is included in the menu items or if both the video composition and trim tool are not included as menu items. Otherwise, the trim tool is used if it is included in your subscription.

File:
class TrimConfiguration(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.
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)
}
// 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 -> {
}
}
}
}
}