在android recyclerview中,多媒体资料视频缩略图的加载速度非常慢

在android recyclerview中,多媒体资料视频缩略图的加载速度非常慢,android,android-studio,android-recyclerview,android-gallery,Android,Android Studio,Android Recyclerview,Android Gallery,我试图在recyclerview中显示本地图库中的所有用户视频缩略图,但加载缩略图的速度非常慢(加载所有视频缩略图几乎需要10秒)。代码如下: VideoGalleryAdapter.java: public class VideoGalleryAdapter extends RecyclerView.Adapter<VideoGalleryAdapter.viewHolder> { public OnItemClickListener onItemClickLis

我试图在recyclerview中显示本地图库中的所有用户视频缩略图,但加载缩略图的速度非常慢(加载所有视频缩略图几乎需要10秒)。代码如下:

VideoGalleryAdapter.java:

    public class VideoGalleryAdapter extends RecyclerView.Adapter<VideoGalleryAdapter.viewHolder> {

    public OnItemClickListener onItemClickListener;
    Context context;
    ArrayList<VideoGalleryModel> videoArrayList;

    public VideoGalleryAdapter(Context context, ArrayList<VideoGalleryModel> videoArrayList) {
        this.context = context;
        this.videoArrayList = videoArrayList;
    }

    @Override
    public VideoGalleryAdapter.viewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.video_list, viewGroup, false);
        return new viewHolder(view);
    }

    @Override
    public void onBindViewHolder(final VideoGalleryAdapter.viewHolder holder, final int i) {
        holder.videoDuration.setText(videoArrayList.get(i).getVideoDuration());
        Glide.with(context).asBitmap().load(videoArrayList.get(i).getVideoThumb()).into(holder.videoThumb);
    }

    @Override
    public int getItemCount() {
        return videoArrayList.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int pos, View v);
    }

    public class viewHolder extends RecyclerView.ViewHolder {
        TextView videoDuration;
        ImageView videoThumb;

        public viewHolder(@NonNull View itemView) {
            super(itemView);
            videoDuration = itemView.findViewById(R.id.videoDuration);
            videoThumb = itemView.findViewById(R.id.videoThumb);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(getAdapterPosition(), v);
                }
            });
        }
    }
}

video_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/mainVideoContainer"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginBottom="5dp"
        android:background="@color/colorBlackTransparent">

        <ImageView
            android:id="@+id/videoThumb"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher_background"
            android:scaleType="centerCrop"/>

        <TextView
            android:id="@+id/videoDuration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="00:06"
            android:padding="5dp"
            android:layout_marginEnd="10dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:fontFamily="@font/gilroysemibold"
            android:textColor="@android:color/white"/>

    </RelativeLayout>

</RelativeLayout>


我只是想知道在recyclerview中显示视频缩略图的正确方法以及如何更快地加载它。如果你还有其他问题,请问我,我很乐意回答。任何帮助都将不胜感激,因为创建视频缩略图是一项繁重的操作。所以这需要时间。 试着评论这些行

//Bitmap bmp = ThumbnailUtils.createVideoThumbnail(data, MediaStore.Video.Thumbnails.MINI_KIND);
 //videoModel.setVideoThumb(bmp);
并使用Glide直接加载图像缩略图

Glide.with(context).load(new File(videoArrayList.get(i).videoUri.toString())).into(holder.videoThumb);
        

Glide可以通过uri加载视频缩略图。您可以共享视频列表和视频画廊模型吗also@KishanMaurya我把它们添加到我的问题中了,先生,您可以查看一下创建视频缩略图的具体原因吗?谢谢,先生。我尝试了Glide.with(context).load(新文件(videoArrayList.get(I).getVideoUri().toString()).into(holder.videoThumb);它的工作原理(稍微有点延迟,但肯定比以前更好),您也可以避免创建位图。由于您现在不使用此位图,因此也可以避免。这将节省大量时间。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/mainVideoContainer"
        android:layout_width="125dp"
        android:layout_height="125dp"
        android:layout_marginBottom="5dp"
        android:background="@color/colorBlackTransparent">

        <ImageView
            android:id="@+id/videoThumb"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher_background"
            android:scaleType="centerCrop"/>

        <TextView
            android:id="@+id/videoDuration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="00:06"
            android:padding="5dp"
            android:layout_marginEnd="10dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentBottom="true"
            android:fontFamily="@font/gilroysemibold"
            android:textColor="@android:color/white"/>

    </RelativeLayout>

</RelativeLayout>
//Bitmap bmp = ThumbnailUtils.createVideoThumbnail(data, MediaStore.Video.Thumbnails.MINI_KIND);
 //videoModel.setVideoThumb(bmp);
Glide.with(context).load(new File(videoArrayList.get(i).videoUri.toString())).into(holder.videoThumb);