I'm trying to record the video and store it in DCIM directory
I have tried to use MediaStore but the problem is the media store returns Uri and MediaRecorder take File, FileDescreptor or file path and I don't have any of these options so I tried to convert Uri to FileDescreptor like this resolver.openFileDescriptor(uri!!, "rw")?.fileDescriptor
but exception happens java.lang.RuntimeException: Error retrieving camcorder profile params
private fun setUpTimeLapseMediaRecorder(): MediaRecorder {
val resolver = context.contentResolver
val contentValues = ContentValues()
val videoName = "time_lapse_video_" + System.currentTimeMillis() + ".mp4"
val directoryName = "${Environment.DIRECTORY_DCIM}"
val filePath = "${directoryName}Videos${File.separator}$videoName"
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, filePath)
val uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues)
val timeLapseMediaRecorder = MediaRecorder()
timeLapseMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE)
timeLapseMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P))
timeLapseMediaRecorder.setOutputFile(/* How i can get file path from media store?*/)
timeLapseMediaRecorder.setVideoFrameRate(60)
timeLapseMediaRecorder.setCaptureRate(1.8)
timeLapseMediaRecorder.prepare()
return timeLapseMediaRecorder
}
How I can use MediaStore with MediaRecorder