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) {
val settingsList = VideoEditorSettingsList(false)
.configure<LoadSettings> {
it.source = uri
}
VideoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
settingsList.release()
}
}