Edited video does not saving as mp4 format android studio-ThrowExceptions

Exception or error:

I am developing a video editing app using kotlin and android. In application code it to, after video edited, video saves automatically to external storage. When triggered save() method video saves in 3gp format(can not open). After long time,it automatically convert to mp4 and working sometimes. there is no error either.
After saving video, I start intent to preview that video.It works fine with edited video.

save() method:

    fun saveVideo() {

    if (ContextCompat.checkSelfPermission(
            this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE
        )
        == PackageManager.PERMISSION_GRANTED
    ) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(
                this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        ) {

        } else {

            ActivityCompat.requestPermissions(
                this,
                arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE),
                RECORD_REQUEST_CODE
            );
        }

        val values = ContentValues(3)
        values.put(MediaStore.Video.Media.TITLE, "trimmed")
        values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")
        getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
    }
}

ScreenShot of gallery:
enter image description here
I cannot find any bug or anything. any one have a clue? what is the matter?

How to solve:

missing line:

            mediaMetadataRetriever.setDataSource(this, uri)

Leave a Reply

Your email address will not be published. Required fields are marked *