Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ThumbnailUtils.createVideoThumbnail returns NULL when capturing new video

Tags:

android

video

I am trying to create a thumbnail from video. I use the following line:

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

It works great when I select an existing video from the gallery, but returns NULL when recording a new video and then trying to get the thumbnail, although the path is valid (/storage/emulated/0/airImagePicker/1394007123308.3gp).

I am on HTC One Android 4.2.2.

Thanks!

like image 621
Light Avatar asked Nov 11 '22 11:11

Light


1 Answers

I faced the same problem and noticed that it worked when there was a delay between taking the video and creating the bitmap. A workaround that worked for me was to retry creating the bitmap with busy waiting until it wasn't null( it took a few seconds). It's clearly not a clean solution but it seems to do the job. example of use (in c# xamarin android)

try {
                Bitmap bitmap = null;
                for (int time = 0; time < 6000; time += timeInterval) {
                    bitmap = ThumbnailUtils.CreateVideoThumbnail (videoFile.Path, ThumbnailKind.MiniKind);
                    if (bitmap != null)
                        break;
                    await Task.Delay (timeInterval);
                }


          return bitmap;

I hope it helps.

like image 107
YehudaW Avatar answered Nov 14 '22 23:11

YehudaW