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