Video file is corrupted while saving mp4 to external storage in android #62686
-
Select Topic AreaQuestion BodyI am trying to save an mp4 file after trimming with the help of its url. I am using https://github.com/a914-gowtham/android-video-trimmer for trimming my video and the updated uri after trimming is fine as I trying playing it in exoplayer and it works, the problem happens when I try to save it to external storage. I can see my file being saved to external storage as well but when I try to play it after saving via third party apps like vlc, mxplayer etc they throw error. So below is my code to save video after getting the uri |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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) |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
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")
…