Domanda

Right now I am creating thumbnail using below method-

 Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
                    MediaStore.Images.Thumbnails.MICRO_KIND);

This method is working fine, The problem is I am getting thumbnail from the beginning of the video (Might be from 00:00 or 00:01).

My Ques is, Can I get Thumbnail from specified position(Let's say 00:05)? Thanks.

È stato utile?

Soluzione

Yes you can by below way..

MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
   retriever.setDataSource(filePath);
   //here 5 means frame at the 5th sec.
    bitmap = retriever.getFrameAtTime(5);
    } catch (Exception ex) {
   // Assume this is a corrupt video file
}

For more info check it MediaMetadataRetriever

Altri suggerimenti

FFmpegMediaMetadataRetriever will accomplish what you want and it works with API 7+:

FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever();
try {
    retriever.setDataSource(filePath);
    //here 5 means frame at the 5th sec.
    bitmap = retriever.getFrameAtTime(5);
} catch (Exception ex) {
    // Assume this is a corrupt video file
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top