我正在尝试使用Picasso
来加载视频缩略图,不幸的是,似乎没有任何事情发生,imageview保持空白。
VideoRequestHandler videoRequestHandler;
Picasso picassoInstance;
videoRequestHandler = new VideoRequestHandler();
picassoInstance = new Picasso.Builder(context.getApplicationContext())
.addRequestHandler(videoRequestHandler)
.build();
String fileName = "android.resource://" + mContext.getPackageName() + "/" + R.raw.default_video;
holder.searchVideoViewItem.setVideoURI(Uri.parse(fileName));
picassoInstance.load(videoRequestHandler.SCHEME_VIDEO+":"+fileName).into(holder.searchVideoViewItemThumb);
public class PicassoVideoFrameRequestHandler extends RequestHandler {
public String SCHEME_VIDEO="video";
@Override
public boolean canHandleRequest(Request data)
{
String scheme = data.uri.getScheme();
return (SCHEME_VIDEO.equals(scheme));
}
@Override
public Result load(Request data, int arg1) throws IOException
{
Bitmap bm = ThumbnailUtils.createVideoThumbnail(data.uri.getPath(), MediaStore.Images.Thumbnails.MINI_KIND);
return new Result(bm, Picasso.LoadedFrom.DISK);
}
}
<RelativeLayout
android:layout_width="75dp"
android:layout_height="75dp"
android:background="@drawable/com_facebook_button_blue"
android:id="@+id/searchVideolayout"
android:layout_below="@+id/searchImageViewItem">
<VideoView
android:id="@+id/searchVideoViewItem"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="20dp"/>
<ImageView
android:id="@+id/searchVideoThumbViewItem"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="20dp"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/success"
android:id="@+id/searchVideoPlay"
/>
</RelativeLayout>
答案 0 :(得分:0)
我建议您根据ThumbnailUtils.createVideoThumbnail()
编写自己的类。创建MediaMetadataRetriever的实例,将数据源设置为您的内容URI,然后getFrameAtTime(1000)
以获取帧,例如1秒。这会给你一个位图。确保你释放了猎犬!
获得位图后,计算目标宽度和高度(可以使用此example in docs),然后执行
bitmap = ThumbnailUtils.extractThumbnail(bitmap,dstWidth, dstHeight, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
此外,我建议您在AsyncTask中执行所有操作,因为使用位图的速度很慢。 A good example is again in the docs here