应用 MediaMetadataRetriever类获取视频缩略图

使用 MediaMetadataRetriever类获取视频缩略图 使用代码private Bitmap getThumbnail(Context paramContex

使用 MediaMetadataRetriever类获取视频缩略图

 

使用代码

private Bitmap getThumbnail(Context paramContext, long paramLong, Uri paramUri)
    {
      MediaMetadataRetriever localMediaMetadataRetriever = new MediaMetadataRetriever();
      Bitmap localBitmap1;
      try
      {
        localMediaMetadataRetriever.setDataSource(paramContext, paramUri);//获取图像前必须先设置dataSource
     
        Bitmap localBitmap2 = localMediaMetadataRetriever.getFrameAtTime(1000L * paramLong);//获取指定时间视频文件图像
        localBitmap1 = localBitmap2;
        if(localBitmap1==null){
         localBitmap1=BitmapFactory.decodeResource(paramContext.getResources(), R.drawable.ic_video_default);
        }
        return localBitmap1;
      }
      catch (RuntimeException localRuntimeException)
     
      {
        Log.d("SecVideoWidgetProvider", "getThumbnail localRuntimeException");
        return null ;
      }
 
    }