ThumbnailUtils.createVideoThumbnail 在捕获新视频时返回 NULL [英] ThumbnailUtils.createVideoThumbnail returns NULL when capturing new video

查看:21
本文介绍了ThumbnailUtils.createVideoThumbnail 在捕获新视频时返回 NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从视频创建缩略图.我使用以下行:

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

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

当我从图库中选择现有视频时效果很好,但在录制新视频然后尝试获取缩略图时返回 NULL,尽管路径有效 (/storage/emulated/0/airImagePicker/1394007123308.3gp).

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).

我使用的是 HTC One Android 4.2.2.

谢谢!

推荐答案

我遇到了同样的问题,并注意到它在拍摄视频和创建位图之间存在延迟时起作用.对我有用的解决方法是重试创建位图,忙着等待直到它不为空(花了几秒钟).这显然不是一个干净的解决方案,但它似乎可以完成这项工作.使用示例(在 c# xamarin android 中)

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;

希望能帮到你.

这篇关于ThumbnailUtils.createVideoThumbnail 在捕获新视频时返回 NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆