3

I would like to save my new created video file under gallery dir, I found such way to do it

https://stackoverflow.com/a/11746999/5709159

    @Nullable
    public Uri addVideo(@NonNull final File videoFile, @NonNull final String iVideoName) {
        ContentValues values = new ContentValues(3);
        values.put(MediaStore.Video.Media.TITLE, iVideoName);
        values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
        values.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());

        return getApplication().getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
    }

But I noticed that all video file that were saved, were saved without duration, like you open the gallery you can find your video file but time that you see on your video file is 00:00, but if you open the file it has full video duration (let's say 15 seconds duration).

I found that there is MediaStore.Video.Media.DURATION value that you can set as one more value for ContentValues, for example:

values.put(MediaStore.Video.Media.DURATION, 20);

But then I got a warning that this value DURATION could be using from Q android version...

So, what is the solution for other devices?

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121
  • Can't mark as duplicate, but this seems a solution: https://stackoverflow.com/questions/36769579/android-how-to-set-meta-data-to-mp4-file – Jake Lee Dec 28 '19 at 20:21

0 Answers0