0
我想用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);
PicassoVideoFrameRequestHandler
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);
}
}
Layout.xml
<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>
如果我正确理解你的代码,'data.uri.getPath()'实际上是一个'android.resource'方案,因此不会引用视频。 FWIW,[这里是我的示例应用程序](https://github.com/commonsguy/cw-omnibus/tree/master/Media/VideoList)使用Universal Image Loader加载视频缩略图。 – CommonsWare
我从应用程序本身拉一个drawable进行测试。 – Lion789
'ThumbnailUtils.createVideoThumbnail()'不会知道如何加载可绘制资源。 – CommonsWare