0

I am trying to make a gif app on android. The gifs are made and saved in ExternalStoragePublicDirectory. Now I am trying to get those files and show it in a recyclerview using MediaMetadataReteiver by passing the files to the adapter. Below is the code in the onBindViewHolder().

Log.d("GifAdapter: ", files[position].getAbsolutePath());
try {
retriever.setDataSource(files[position].getAbsolutePath());
holder.mImageView.setImageBitmap(retriever.getFrameAtTime(1000000, OPTION_CLOSEST_SYNC));
} catch (Exception e) {
e.printStackTrace();
}

It gives me RuntimeException: setDataSource failed: status = 0x80000000. I tried using a different directory containing video files. It worked and i got the frames to display. But when i use it with gifs it gives me runtime exception. What should i do to get the gifs displayed. Thanks!

Tsar
  • 63
  • 2
  • 10
  • Why don't you use an image library like glide or something? Check this link, might be helpful https://stackoverflow.com/a/48971859/4978133 – Clint Paul May 16 '18 at 09:08
  • @ClintPaul Thankyou for your reply i used it, and gifs are displayed too, but now i am getting out of memory exception, though the app isn't crashing. it would have been great if i was to show only the thumbnails. – Tsar May 16 '18 at 09:21
  • 'GlideApp .with(context) .asBitmap() .load(gifUrl) .into(imageViewGifAsBitmap);' Try this, It'll only show the first frame of the GIF. – Clint Paul May 16 '18 at 09:27
  • 1
    Thanks @Clint Paul. – Tsar May 16 '18 at 09:33

1 Answers1

0

Use Glide to show Gifs. It will handle gifs and Images for you

https://github.com/bumptech/glide

Sucho
  • 321
  • 1
  • 14
  • Hey man thanks for your reply i used it, and gifs are displayed too, but now i am getting out of memory exception, though the app isn't crashing. it would have been great if i was to show only the thumbnails. – Tsar May 16 '18 at 09:22
  • You cannot show the full sized images or gifs. So if the thumbnail imageview size is 100x100 and you load a 1000x1000 image in it, memory usage will be high. You need to decrease the image size so that the memory usage is low – Sucho May 16 '18 at 09:25
  • Both the answers helped me actually thanks Sucho and Clint Paul – Tsar May 16 '18 at 09:32