2

I am dealing with the thumbnail in Android. Even though I use the function ThumbnailUtils.createVideoThumbnail provided by Android, it gets black bitmap.

I start my research and find out some links:
1/ Thumbnail null
2/ Video Thumbnail return null

However, I checked my returned bitmap and figure out that it is not null.

Please let me know if you have any ideas.

Any suggestion would be appreciated. Thank you in advance!

Community
  • 1
  • 1
Luong Truong
  • 1,953
  • 2
  • 27
  • 46
  • you can Also do this , It's better approach I think http://stackoverflow.com/a/34082262/1462770 – Amir Apr 27 '16 at 05:00

3 Answers3

0

You can use this method to create Thumbnail

private Bitmap getThumbnailBitmap(String file_name,String file_type)
    {
        try
        {
            String file_path= Environment.getExternalStorageDirectory()+File.separator+ Constants.APP_FOLDER_NAME+File.separator+ Constants.ATTACHMENTS_FOLDER_NAME+File.separator+file_name;
            if(file_type.equals(Constants.FILE_TYPE_IMAGE))
            {
                int dimens=(int) Env.currentActivity.getResources().getDimension(R.dimen.thumbnailHW);
                FileInputStream fis = new FileInputStream(file_path);
                Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
                return ThumbnailUtils.extractThumbnail(imageBitmap, dimens, dimens);

            }
            else if(file_type.equals(Constants.FILE_TYPE_VIDEO))
            {

                return ThumbnailUtils.createVideoThumbnail(file_path, MediaStore.Video.Thumbnails.MICRO_KIND);
            }
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }
Nitesh Pareek
  • 362
  • 2
  • 10
  • Thank you for your answer. I will have a try and mark it as an answer if it works. – Luong Truong Apr 27 '16 at 01:21
  • I know exactly my input files are video and the code I use to get the thumbnail is exactly what you are using `ThumbnailUtils.createVideoThumbnail(file_path, MediaStore.Video.Thumbnails.MICRO_KIND);` Do you have any suggestion? – Luong Truong Apr 27 '16 at 02:34
  • This code create Thumbnail of video if you want create thumbnail of an image then use this code ThumbnailUtils.createVideoThumbnail(file_path, MediaStore.Images.Thumbnails.MICRO_KIND); – Nitesh Pareek Apr 27 '16 at 04:04
0

Check this one

Bitmap ThumbnailUtils.createVideoThumbnail("picturePath", MediaStore.Video.Thumbnails.MINI_KIND);
DKV
  • 1,767
  • 3
  • 28
  • 49
  • Thank you for giving the answer. That function is exactly what i am doing to get the thumbnail. But I do not know why it return a black thumbnail. – Luong Truong Apr 27 '16 at 01:22
  • did u check your video path? – DKV Apr 27 '16 at 05:16
  • all the videos i am store in a folder, but there are some video could not get the thumbnail, not all of them. – Luong Truong Apr 27 '16 at 08:47
  • 1
    Yes, I did, all of them in .mp4. I wonder why there are only a few videos can have the thumbnail and the other return black thumbnail, not null. I get the thumbnail from the middle of the video and there is not a black frame so it should not be black thumbnail. – Luong Truong Apr 28 '16 at 02:24
0

IF this method getThumbnailBitmap(); returns Bitmap Null this issue occurs some devices so use below code

Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(
                getActivity().getContentResolver(),
                ContentUris.parseId(intent.getData()),
                MediaStore.Video.Thumbnails.MICRO_KIND,
                (BitmapFactory.Options) null ); 
Nitesh Pareek
  • 362
  • 2
  • 10
  • I am able to receive the bitmap, but it is a black thumbnail. I get the thumbnail from the middle of the video and there is an image so it should not be black – Luong Truong Apr 28 '16 at 02:26