Frage

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.

War es hilfreich?

Lösung

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

Andere Tipps

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
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top