Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Display a video thumbnail from a URL

Tags:

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

enter image description here

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);         }      } 
like image 380
Cool Avatar asked May 07 '14 15:05

Cool


People also ask

Which tool is used to display the thumbnail of a video in Android?

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.

How do I get the thumbnail from a video URL in flutter?

Just enter the url of the video into the ThumbnailImage() widget. You can also output the image as Uint8List. Supports Android, IOS & Web.


1 Answers

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; } 
like image 90
KishuDroid Avatar answered Sep 28 '22 09:09

KishuDroid