使用代码
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 ;
}
}
本文介绍了一种通过Java代码从视频中提取特定时间点图像的方法。利用MediaMetadataRetriever组件设置数据源并获取指定时间戳处的帧,如果获取失败则采用默认图片。
1914

被折叠的 条评论
为什么被折叠?



