Skip to main content
Language

From Camera

Start Camera#

Start the camera for result using the ACTION_VIDEO_CAPTURE action.

Handle Camera Result#

If the camera exits with Activity.RESULT_OK, we get the Uri of the captured video using Intent.getData().

Start Editor#

Configure the LoadSettings to set the source to the Uri of the captured video. The VideoEditorBuilder takes in the configured VideoEditorSettingsList and starts the video editor. The result is obtained in the onActivityResult() method when the editor exits.

class OpenVideoFromCamera(private val activity: AppCompatActivity) : Example(activity) {
companion object {
private const val CAMERA_REQUEST_CODE = 0x69
}
override fun invoke() {
val takeVideoIntent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
try {
activity.startActivityForResult(takeVideoIntent, CAMERA_REQUEST_CODE)
} catch (ex: ActivityNotFoundException) {
showMessage("No Camera app installed")
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
when (requestCode) {
EDITOR_REQUEST_CODE -> {
intent ?: return
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
CAMERA_REQUEST_CODE -> {
if (resultCode == Activity.RESULT_OK) {
intent?.data?.let { showEditor(it) } ?: showMessage("Invalid Uri")
}
}
}
}
private fun showEditor(uri: Uri) {
// 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 = uri
}
// 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()
}
}