0

I want to create a custom gallery like that used in Instagram.I need to get all images and videos and show them in a Recyclerview. If a user click on an image thumbnail, that image will show on top of the page and If a user click on a video thumbnail, that video will play on top of the page. I used LoaderManager in my fragment and get all images and videos with one cursor as described here

the following is a piece of my fragment code

   @NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
    String[] projection = {
            MediaStore.Files.FileColumns._ID,
            MediaStore.Files.FileColumns.DATA,
            MediaStore.Files.FileColumns.DATE_ADDED,
            MediaStore.Files.FileColumns.MEDIA_TYPE,
            MediaStore.Files.FileColumns.MIME_TYPE,
            MediaStore.Files.FileColumns.TITLE
    };

    String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
            + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
            + " OR "
            + MediaStore.Files.FileColumns.MEDIA_TYPE + "="
            + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;

    Uri queryUri = MediaStore.Files.getContentUri("external");

    CursorLoader cursorLoader = new CursorLoader(
            getContext(),
            queryUri,
            projection,
            selection,
            null, // Selection args (none).
            MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
    );


    return cursorLoader;
}

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {

    recyclerView.setAdapter(new GalleryAdapter(getContext(), data, this));
}

My problem is that I need thumbnail of images and videos not the original one how can I do that?

Fahime Ghasemi
  • 775
  • 9
  • 13

1 Answers1

0

you can fetch Thumbnail of videos like this

Bitmap bitmap = ThumbnailUtils.createVideoThumbnail("file_path",
                MediaStore.Video.Thumbnails.MINI_KIND);
Omid Ziyaee
  • 420
  • 4
  • 16