• Wallwave (formerly MIUI wallpaper app) is the hd wallpapers app containing stock wallpapers, other photo background HD wallpapers app and best free ringtones. This is a free HD wallpaper app for android phones that supports all devices. …

Hello coders,

Here we show you a code that can be helpful for getting thumbnail from video URL.

public static Bitmap retriveVideoFrameFromVideo(String videoPath) throws Throwable {
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
throw new Throwable("Exception in retriveVideoFrameFromVideo(String videoPath)" + e.getMessage());

} finally {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
}
return bitmap;
}

Usage:

try {
bitmap = retriveVideoFrameFromVideo("https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4");
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}

If you want to change its width and height, then create scaledBitmap:

if (bitmap != null) {
bitmap = Bitmap.createScaledBitmap(bitmap, 240, 240, false);
imageView.setImageBitmap(bitmap);
}

Sometimes you will get MediaRetriever exception. So if you a have better solution, then write here and make this post more helpful.

Output

Droid By Me

By profession and passion : Android Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store