display images and videos in android Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of display images and videos in android without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I was trying to list all the images and videos in a folder but setting it in recyclerview nor gridview gives a good result. it stucks in the scroll. Please suggest a way how to display all the files in a better way.

This is how i fetch files,

listFile = AllUtils.getFiles(fetchPath, mContext);

displaying part in recyclerview

public void onBindViewHolder(@NonNull DetailViewHolder holder, final int position) {
    if (listFile.get(position).toString().contains("mp4")) {
        Bitmap myBitmap = ThumbnailUtils.createVideoThumbnail(listFile.get(position).toString(), MediaStore.Video.Thumbnails.MINI_KIND);
        holder.ivIcon.setImageBitmap(myBitmap);
        holder.ivPlay.setVisibility(View.VISIBLE);
    }
}

Answer

There are various free open-source libraries are available for android on GitHub for working with images and videos.

I think using BitMap for displaying images is not a good idea instead of BitMap you should use Glide library for displaying images and use fenster for videos.

Import Glide in your project

repositories {
  mavenCentral()
  google()
}

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.7.1'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
}

Display Image like this:

  GlideApp
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .into(myImageView);

You can also upload image using url

  GlideApp.with(this).load("http://........").into(imageView);

read more about glide and fenster.

We are here to answer your question about display images and videos in android - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji