I am a beginner in Kotlin, and just started Kotlin. I am trying to get thumbnail from a video that i recorded within my app.
I have tried almost everything that i possibly can, but everytime i get NULL.
So first of all, i added the permission of READ_EXTERNAL_STORAGE in the manifest (i don't know, maybe it's required or not)
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
i have a video file that i created using:
fun createVideoFile(): File {
val fileName = "GameXVideo"
val storageDir = getExternalFilesDir(Environment.DIRECTORY_MOVIES)
return File.createTempFile(fileName, "mp4", storageDir)
}
so i am not saving the video in the physical storage. right after finishing recording, i am playing back this recorded video, and it is working pretty fine.
The next thing i want to get is it's thumbnail, i have tried lots of already given answers but i cannot get it done. here is what i have already tried:
val videoFile = intent.extras?.get("videoFile") as? File // getting videoFile from the intent
val videoPath = videoFile?.absolutePath // getting its absolute path
val videoUri = Uri.fromFile(videoFile) // getting its uri
Method 1:
val bMap = ThumbnailUtils.createVideoThumbnail(videoPath!!, MediaStore.Video.Thumbnails.MICRO_KIND) // gives null
Method 2:
val mMMR = MediaMetadataRetriever()
mMMR.setDataSource(this, videoUri)
val bmp = mMMR.frameAtTime // also gives null
Method 3:
val asd: InputStream? = contentResolver.openInputStream(videoUri)
val bmap2 = BitmapFactory.decodeStream(asd)
asd?.close()
Method 4:
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
val cursor = this.contentResolver.query(videoUri, filePathColumn, null, null, null)
cursor?.moveToFirst()
val columnIndex = cursor?.getColumnIndex(filePathColumn[0])
val picturePath = cursor?.getString(columnIndex!!)
cursor?.close()
your HELP will be highly appreciated. Thank you.