Skip to content

Video file is corrupted while saving mp4 to external storage in android #62686

Answered by dominayo
Doraemon730 asked this question in Mobile
Discussion options

You must be logged in to vote

You can use this method to save the video in device's having android 10 or above.

Just pass the file and display name.

@RequiresApi(api = Build.VERSION_CODES.Q)
@throws(FileNotFoundException::class)
fun Context.addVideoToGalleryAPI29(
file: File,
displayName: String,
exportListener: VideoExportListener
) {
val savePath = (Environment.DIRECTORY_DCIM
+ File.separator + file.name)
val cv = ContentValues()
cv.put(
MediaStore.Video.Media.RELATIVE_PATH, Environment.DIRECTORY_DCIM
+ File.separator + File(savePath).name
)
cv.put(MediaStore.Video.Media.TITLE, "${displayName}.mp4")
cv.put(MediaStore.Video.Media.DISPLAY_NAME, "${displayName}.mp4")
cv.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Doraemon730
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Mobile
Labels
Mobile Triage your notifications and browse code on the go with the GitHub Mobile app Question
2 participants