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
toALWAYS
. forceTrimMode
is set toIF_NEEDED
as in our example and will only present- the composition tool, if your initial composition is longer than
maximumVideoLength
or shorter thanminimumVideoLength
, or - the trim tool, if your initial video is longer than
maximumVideoLength
.
- the composition tool, if your initial composition is longer than
- Setting
forceTrimMode
toSILENT
will automatically trim the video to themaximumVideoLength
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 constructorval 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-maxit.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_CODEVideoEditorBuilder(activity).setSettingsList(settingsList).startActivityForResult(activity, EDITOR_REQUEST_CODE)// Release the SettingsList once donesettingsList.release()}override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {intent ?: returnif (requestCode == EDITOR_REQUEST_CODE) {// Wrap the intent into an EditorSDKResultval result = EditorSDKResult(intent)when (result.resultStatus) {EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")else -> {}}}}}