Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: how to get a video thumbnail of a file that's private to your application?
    text
    copied!<h2>Question:</h2> <p>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?</p> <h2>Background:</h2> <ol> <li>My application includes a camera that can record video.</li> <li>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: <a href="http://developer.android.com/reference/android/content/Context.html#openFileOutput%28java.lang.String,%20int%29" rel="noreferrer"><code>Context#openFileOutput(fileName, Context.MODE_PRIVATE)</code></a> - a typical file path looks like this: <code>/data/data/[package.name]/files/[fileName].mp4</code> -- FYI I already tried using <code>Context.MODE_WORLD_READABLE</code> instead of <code>Context.MODE_PRIVATE</code> but it didn't help.</li> <li>Even though the video may eventually end up in external storage (by moving the file to <a href="http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory%28java.lang.String%29" rel="noreferrer"><code>Environment#getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)</code>)</a>, the thumbnail <em>must</em> be displayed while the video is in application-private storage.</li> <li><p>It seems like <a href="http://developer.android.com/reference/android/media/ThumbnailUtils.html#createVideoThumbnail%28java.lang.String,%20int%29" rel="noreferrer"><code>ThumbnailUtils.createVideoThumbnail(String, int)</code></a> works fine for the file after it is moved to the public directory (regardless of adding it to the MediaStore), but silently fails (returns <code>null</code>) when the file is in internal storage.</p> <ul> <li>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.</li> </ul></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload