I need to display a video thumbnail based to a URL into an ImageView
view child of my ListView
items, i have found this post but not worked.
Result
Code
thumb_image.setImageBitmap(new LoadVideoThumbnail().execute(URLs.videos +"/"+videos.get(position).getId()+".mp4").get());
AsyncTask
public class LoadVideoThumbnail extends AsyncTask<String, Object, Bitmap>{ @Override protected Bitmap doInBackground(String... objectURL) { //return ThumbnailUtils.createVideoThumbnail(objectURL[0], Thumbnails.MINI_KIND); return ThumbnailUtils.extractThumbnail(ThumbnailUtils.createVideoThumbnail(objectURL[0], Thumbnails.MINI_KIND), 100, 100); } @Override protected void onPostExecute(Bitmap result){ //img.setImageBitmap(result); } }
Which tool is used to display the thumbnail of a video in Android? Many of the application are using the Glide library for loading the Image and Video thumbnail. You can download the Glide Library from here and alternatively, you can include the library directly in your app using Gradle.
Just enter the url of the video into the ThumbnailImage() widget. You can also output the image as Uint8List. Supports Android, IOS & Web.
Without downloading video you can generate thumbnail of video by using below method :
public static Bitmap retriveVideoFrameFromVideo(String videoPath)throws Throwable { Bitmap bitmap = null; MediaMetadataRetriever mediaMetadataRetriever = null; try { mediaMetadataRetriever = new MediaMetadataRetriever(); if (Build.VERSION.SDK_INT >= 14) mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>()); else mediaMetadataRetriever.setDataSource(videoPath); // mediaMetadataRetriever.setDataSource(videoPath); bitmap = mediaMetadataRetriever.getFrameAtTime(1, MediaMetadataRetriever.OPTION_CLOSEST); } catch (Exception e) { e.printStackTrace(); throw new Throwable("Exception in retriveVideoFrameFromVideo(String videoPath)"+ e.getMessage()); } finally { if (mediaMetadataRetriever != null) { mediaMetadataRetriever.release(); } } return bitmap; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With