Search code examples
androidandroid-videoviewandroid-glide

how get frame from video url and show in ImageView


I use glide to get frame from video url but glide for get frame, download the whole video and it takes time.

        RequestOptions myOptions = new RequestOptions()
            .fitCenter()
            .centerCrop().circleCrop()
            .placeholder(R.drawable.loading_circle);

       Glide.with(context)
            .asBitmap()
            .apply(myOptions)
            .load(Link)
            .into(image);

How can I get the last frame from the video?


Solution

  • you can use MediaMetadataRetriever for doing that , you can also use url , code sample from here ,

    .....

    String url = "yoururl";
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ImageView capturedImageView = (ImageView)findViewById(R.id.capturedimage);
    
      MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    
      mediaMetadataRetriever .setDataSource(url, new HashMap<String, String>());
      Bitmap bmFrame = mediaMetadataRetriever.getFrameAtTime(1000); //unit in microsecond
      capturedImageView.setImageBitmap(bmFrame);
     }