Code example for MediaMetadataRetriever

Methods: getFrameAtTime, release, setDataSource

0
        return createThumbnail(uri, bitmap, orientation);
    } 
 
    public static Bitmap createVideoThumbnail(FileDescriptor fd, int targetWidth) {
        return createVideoThumbnail(null, fd, targetWidth);
    } 
 
    public static Bitmap createVideoThumbnail(String filePath, int targetWidth) {
        return createVideoThumbnail(filePath, null, targetWidth);
    } 
 
    private static Bitmap createVideoThumbnail(String filePath, FileDescriptor fd, int targetWidth) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try { 
            if (filePath != null) {
                retriever.setDataSource(filePath);
            } else { 
                retriever.setDataSource(fd);
            } 
            bitmap = retriever.getFrameAtTime(-1);
        } catch (IllegalArgumentException ex) {
            // Assume this is a corrupt video file 
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file.