Skip to main content
You're viewing documentation for a previous version of this software.Switch to the latest stable version
VESDK/Android

Record a video using the camera app

The Android way of delegating actions to other applications is to invoke an Intent that describes what you want done. This process involves three pieces: The Intent itself, a call to start the external Activity, and some code to handle the video when focus returns to your application.

Here's a function that invokes an intent to capture video.

Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, VIDEO_ACTIVITY_RESULT);
}

Notice that the startActivityForResult() method is protected by a condition that calls resolveActivity(), which returns the first activity component that can handle the intent. Performing this check is important because if you call startActivityForResult() using an intent that no app can handle, your app will crash. So as long as the result is not null, it's safe to use the intent.

Edit the video#

The Android Camera application returns the video in the Intent delivered to onActivityResult() as a Uri pointing to the video location in storage. The following code retrieves this video and pass it to the VideoEditor

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == VIDEO_ACTIVITY_RESULT) {
Uri videoUri = data.getData();
VideoEditorSettingsList settingsList = ExampleConfigUtility.createInitialVesdkSettingsList();
settingsList
.getSettingsModel(LoadSettings.class)
.setSource(videoUri);
new VideoEditorBuilder(VideoCameraActivity.this)
.setSettingsList(settingsList)
.startActivityForResult(VideoCameraActivity.this, EDITOR_ACTIVITY_RESULT, new String[]{});
}
}