1

I am trying to display a thumbnail for my videoview, I have an imageview layered ontop that I want to place a thumbnail... I tried this but it is not working not sure if the url which is being passed as a string is the problem? No errors and the image just does not display the placeholder shows though, so it has to do with either the way I am doing the bitmap, the link also shows the video correctly.

String filePath = ""http://unknown.com/v3-1aox9d1.mp4""; 

ImageView imageview_micro = (ImageView)findViewById(R.id.thumbnail_micro);

Bitmap bmThumbnail;

//MICRO_KIND, size: 96 x 96 thumbnail
bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND);
imageview_micro.setImageBitmap(bmThumbnail);
Lion789
  • 4,402
  • 12
  • 58
  • 96
  • Are you trying to read the thumbnail on the main thread ? – Preethi Rao Jul 27 '15 at 06:39
  • Yeah is that a problem? – Lion789 Jul 28 '15 at 06:09
  • 1
    it may not cause any big problem but usually fetching thumbnail from video will take time and as said by oberflansch your file should be locally available you cant pass the url link of video. If you want to have the thumbanail of video which is currently available in the server then your server has to take the responsibility of storing the thumbanil of the video – Preethi Rao Jul 28 '15 at 06:22
  • How do I grab the filepath from the video thumbnail (bitmap) if it is local – Lion789 Jul 29 '15 at 16:36
  • If the video is locally exist the pass the video path to the above method it will return you the the thumbnail that u can locally store wherever you want – Preethi Rao Jul 30 '15 at 04:52
  • I am not sure I understand I want to grab the video thumbnail path and send it over to my servers to store... I cannot use the video path because it will result in an mp4... – Lion789 Jul 30 '15 at 16:41

2 Answers2

1

That is not the way to use createVideoThumbnail.

The first parameter should be a file path which refers to a local file. You are using a web url.

You have to download the video first or have to search for an other solution.

This answer might help you: https://stackoverflow.com/a/23523205/5038873

Community
  • 1
  • 1
daemmie
  • 6,361
  • 3
  • 29
  • 45
  • Ok but I need to find the source of the bitmap (the file path or uri) to be able to send it to my servers, how do I do that? – Lion789 Aug 01 '15 at 20:36
0

Can you please try below code, it may help you

public static Bitmap retriveVideoFrameFromVideo(String p_videoPath)
        throws Throwable
{
    Bitmap m_bitmap = null;
    MediaMetadataRetriever m_mediaMetadataRetriever = null;
    try
    {
        m_mediaMetadataRetriever = new MediaMetadataRetriever();
        m_mediaMetadataRetriever.setDataSource(p_videoPath);
        m_bitmap = m_mediaMetadataRetriever.getFrameAtTime();
    }
    catch (Exception m_e)
    {
        throw new Throwable(
                "Exception in retriveVideoFrameFromVideo(String p_videoPath)"
                        + m_e.getMessage());
    }
    finally
    {
        if (m_mediaMetadataRetriever != null)
        {
            m_mediaMetadataRetriever.release();
        }
    }
    return m_bitmap;
}

 Bitmap bmThumbnail;
 bmThumbnail  = retriveVideoFrameFromVideo(filePath);
 imageview_micro.setImageBitmap(bmThumbnail);