Android Video Thumbnail Create createVideoThumbnail(String filePath, int size)

Here you can find the source of createVideoThumbnail(String filePath, int size)

Description

create Video Thumbnail

Declaration

public static Bitmap createVideoThumbnail(String filePath, int size) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

import android.media.MediaMetadataRetriever;

public class Main {
    public static Bitmap createVideoThumbnail(String filePath, int size) {
        Bitmap bitmap = null;// www.  j a  va  2  s .  co m
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            retriever.setDataSource(filePath);
            bitmap = retriever.getFrameAtTime(-1);
        } catch (IllegalArgumentException ex) {
            // Assume this is a corrupt video file
            ex.printStackTrace();
        } catch (RuntimeException ex) {
            // Assume this is a corrupt video file.
            ex.printStackTrace();
        } finally {
            try {
                retriever.release();
            } catch (RuntimeException ex) {
                // Ignore failures while cleaning up.
            }
        }

        if (bitmap == null)
            return null;

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int max = Math.max(width, height);
        if (max > 512) {
            float scale = 512f / max;
            int w = Math.round(scale * width);
            int h = Math.round(scale * height);
            bitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
        }
        return bitmap;
    }
}

Related

  1. createVideoThumbnail(String filePath)
  2. getVideoThumbnail(String videoPath, int width, int height, int kind)
  3. getVideoThumbnail(String videoPath, int width, int height, int kind)
  4. createVideoThumbnail(String imagePath, int kind)