Question:
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?
Background:
- My application includes a camera that can record video.
- For product reasons, the video file is initially created and written in private mode in the application's private data directory, making it private to the application. This is done using:
Context#openFileOutput(fileName, Context.MODE_PRIVATE)
- a typical file path looks like this:/data/data/[package.name]/files/[fileName].mp4
-- FYI I already tried usingContext.MODE_WORLD_READABLE
instead ofContext.MODE_PRIVATE
but it didn't help. - Even though the video may eventually end up in external storage (by moving the file to
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 (returnsnull
) when the file is in internal storage.- Note: as long as the video file is in application-private storage, it is not added to the MediaStore (the image/video content provider on the device Gallery feeds on). Only once the video is moved to external storage do I add it the MediaStore. This is a product-related decision which I cannot circumnavigate; unless there's a way to add the video the media store without it being visible to other apps... I wonder if videos in application-private storage can be added to the media store and would remain application-private but gain all the free "services" provided by the media store such as thumbnail generation.