public static Bitmap createVideoThumbnail(String filePath,int kind,long timeUs){
  Log.i(TAG,"createVideoThumbnail");
  Bitmap bitmap=null;
  MediaMetadataRetriever retriever=new MediaMetadataRetriever();
  try {
    Log.i(TAG,"createVideoThumbnail --1--");
    retriever.setDataSource(filePath);
    bitmap=retriever.getFrameAtTime(timeUs);
  }
 catch (  IllegalArgumentException ex) {
  }
catch (  RuntimeException ex) {
  }
 finally {
    Log.i(TAG,"createVideoThumbnail --2--");
    try {
      Log.i(TAG,"createVideoThumbnail --3--");
      retriever.release();
    }
 catch (    RuntimeException ex) {
    }
  }
  if (bitmap == null) {
    Log.i(TAG,"bitmap is null");
    return null;
  }
  if (kind == Images.Thumbnails.MINI_KIND) {
    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,width,height,true);
    }
  }
 else   if (kind == Images.Thumbnails.MICRO_KIND) {
    Log.i(TAG,"createVideoThumbnail --4--");
    bitmap=extractThumbnail(bitmap,TARGET_SIZE_MICRO_THUMBNAIL,TARGET_SIZE_MICRO_THUMBNAIL,0x2);
  }
  return bitmap;
}

public static Bitmap createVideoThumbnail ( String filePath , int kind , long timeUs ) { Log . i ( TAG , "createVideoThumbnail" ) ; Bitmap bitmap = null ; MediaMetadataRetriever retriever = new MediaMetadataRetriever ( ) ; try { Log . i ( TAG , "createVideoThumbnail --1--" ) ; retriever . setDataSource ( filePath ) ; bitmap = retriever . getFrameAtTime ( timeUs ) ; } catch ( IllegalArgumentException ex ) { } catch ( RuntimeException ex ) { } finally { Log . i ( TAG , "createVideoThumbnail --2--" ) ; try { Log . i ( TAG , "createVideoThumbnail --3--" ) ; retriever . release ( ) ; } catch ( RuntimeException ex ) { } } if ( bitmap == null ) { Log . i ( TAG , "bitmap is null" ) ; return null ; } if ( kind == Images . Thumbnails . MINI_KIND ) { 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 , width , height , true ) ; } } else if ( kind == Images . Thumbnails . MICRO_KIND ) { Log . i ( TAG , "createVideoThumbnail --4--" ) ; bitmap = extractThumbnail ( bitmap , TARGET_SIZE_MICRO_THUMBNAIL , TARGET_SIZE_MICRO_THUMBNAIL , 0x2 ) ; } return bitmap ; }
create a video thumbnail for a video . may return null if the video is corrupt or the format is not supported .
