How to get the Uri of the video captured with registerForActivityResult() in android?

259 Views Asked by At

I am trying to capture a video through the camera in my application, I am using registerForActivityResult() because startActivityForResult() has been deprecated. I am passing the ActivityResultContracts.CaptureVideo() as a contract in the registerForActivityResult(), but in the lambda function, the 'it' value that is present is a nullable Boolean, unlike ActivityResultContracts.TakePicturePreview(), which has a nullable Bitmap as the 'it' value. The boolean only tells whether the video was successfully saved or not. Please can anyone tell me how to get the Uri of that recorded video?

I am using this code to take and save an image:-

val clickImageLauncher = registerForActivityResult(ActivityResultContracts.TakePicturePreview()) {
    doAnythingWithThisImage(it)  // here, 'it' is a nullable Bitmap -> Bitmap?
}
clickImagelauncher.launch(null)

I want to do something similar for taking a video:-

val recordVideoLauncher = registerForActivityResult(ActivityResultContracts.CaptureVideo()) {
    if (it) {
        Log.d(TAG, "Video Saved!")  // here, 'it' is a nullable Boolean -> Boolean?
    }
    else {
        Log.d(TAG, "Error in saving video!")
    }
}
recordVideoLauncher.launch(Uri.EMPTY)  // -> Line A

It has something to do with the Uri passed in Line A. The documentation shows that Uri.EMPTY equates to "". The official documentation of the ActivityResultContracts.CaptureVideo() says that the recorded video is saved in the provided content Uri. I recently came across 'Uri' class and have very less knowledge about it. Screenshot from the official documentation

Please help me with this!

0

There are 0 best solutions below