How do you get a video thumbnail for an application-private file? Specifically, is there a way to extract video frames from an .mpeg file directly?
Context#openFileOutput(fileName, Context.MODE_PRIVATE)
- a typical file path looks like this: /data/data/[package.name]/files/[fileName].mp4
-- FYI I already tried using Context.MODE_WORLD_READABLE
instead of Context.MODE_PRIVATE
but it didn't help.Environment#getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
), the thumbnail must be displayed while the video is in application-private storage.It seems like ThumbnailUtils.createVideoThumbnail(String, int)
works fine for the file after it is moved to the public directory (regardless of adding it to the MediaStore), but silently fails (returns null
) when the file is in internal storage.
In android, we can use the MediaMetadataRetriever to retrieve a thumbnail image of an online video from its url. MediaMetadataRetriever can be used to retrieve frame and metadata from an input media file. Note that the above code takes some time to get the image.
You can take a screenshot from your video that best explains its contents, or you can use a tool like Photoshop or Canva to overlay text or icons on the image. To make a screen capture on a PC, use the Windows Snipping Tool. For Mac users, hit Command+Shift+4 to select the part of your screen you want to capture.
This works for me: Bitmap thumb = ThumbnailUtils. createVideoThumbnail(filePath, Thumbnails. MINI_KIND);
Of course, you can't use MediaStore stuff for private media. I would use a image process library if it is possible at all. I know OpenCV can do that easily by extracting/resizing a frame. - please look at middle section of page 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With