Androzr
Androzr

Reputation: 65

Get bitmap / thumbnail from a streaming video with format like .mp4, .3gp in Android?

I am working on ListView which on item click redirecting to a video link. I explain my problem :

I have three types of videos :

I am trying to get thumbnail to get it in my ImageView from my item of my ListView. I encoutered a problem, I get Youtube thumbnail, Dailymotion thumbnail but I couldn't get thumbnail for other formats.

I tried to use MediaMetaDataRetriever class but nothing happens.

Here is the line where I tried to get my bitmap :

We are in my VideoAdapter class in the getView method. holder is my ViewHolder class and thumbVideo is my ImageView.

Here is differents lines I tried :

holder.thumbVideo.setImageBitmap(createVideoThumbnail(m_Context, Uri.parse(m_Video.getM_Preview())));

m_Video is my Video class and the method getM_Preview() is getting the link of video thumbnail.

Here is my createVideoThumbnail(Context context, Uri uri) method :

    public Bitmap createVideoThumbnail(Context context, Uri uri) {
    Bitmap bitmap = null;
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try { 
        retriever.setDataSource(context, uri);
        bitmap = retriever.getFrameAtTime(-1);
    } catch (RuntimeException ex) {
    } finally { 
        try { 
            retriever.release();
        } catch (RuntimeException ex) {
        } 
    } 
    return bitmap;
}

I am looking an answer for 4 days. If anybody know how I can do, it'll be helpful

Upvotes: 3

Views: 1950

Answers (1)

Ram Prakash Bhat
Ram Prakash Bhat

Reputation: 1308

you can try like below

       Bitmap thumbnail =ThumbnailUtils.createVideoThumbnail(mVideoUri.getPath(),
                                            MediaStore.Images.Thumbnails.MINI_KIND);
        BitmapDrawable  bitmapDrawable = new BitmapDrawable(getResources(), thumbnail);
videoView.setBackground(bitmapDrawable);

Upvotes: 0

Related Questions