avatarNgenge Senior

Summary

This article provides a solution to extract a video thumbnail from a content Uri on Android using the MediaMetadataRetriever framework.

Abstract

The article discusses the challenge of obtaining a video thumbnail from a content Uri on Android, specifically when using CameraX. The author shares their experience and presents a simple solution using Android's MediaMetadataRetriever framework. The method involves using the MediaMetadataRetriever.getFrameAtTime() function, which should be called after MediaMetaDataRetriever.setDataSource(Content, Uri). The author provides the full source code for reference and mentions that the method returns a bitmap that can be set to an ImageView.

Opinions

  • The author has experience using CameraX on Android.
  • The author found the process of obtaining a video thumbnail from a content Uri challenging.
  • The author believes that the solution they found is relatively easy and only requires two lines of code.
  • The author suggests using Android's MediaMetadataRetriever framework to solve this problem.
  • The author provides the full source code for the solution.
  • The author mentions that the method returns a bitmap that can be set to an ImageView.
  • The author concludes the article by stating that the solution is straightforward.

Get a Video thumbnail from Content Uri on Android

Photo by Jakob Owens on Unsplash

I have been using CameraX on Android for a while now and one of the issues I faced was that after recording a video and getting the video Uri, I needed a thumbnail to display the most recent video in my ImageView. After much research, the solution I fell on was relatively easy. The solution requires just two lines of code.

We will use Android’s MediaMetadataRetriever framework.The method to use is MediaMetadataRetriever.getFrameAtTime(). This method should be called only after calling MediaMetaDataRetriever.setDataSource(Content,Uri). The full source code is shown below.

If the method succeeds, it returns a bitmap and you can set it to an ImageView. This was really a short read right.

Cheers!

Android
Video
Media
Androiddevelopment
Imageview
Recommended from ReadMedium