读书人

应用 MediaMetadataRetriever类获取视

发布时间: 2012-11-21 08:23:25 作者: rapoo

使用 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 ;
}

}

读书人网 >移动开发

热点推荐