MediaStore.Video.Thumbnails.getThumbnail()返回null [英] MediaStore.Video.Thumbnails.getThumbnail() returns null
问题描述
我有以下的code;
I have the following code;
String[] projection = { MediaStore.Video.VideoColumns._ID, MediaStore.Video.VideoColumns.DATA };
//String selection = MediaStore.Video.VideoColumns.KIND + "=" + MediaStore.Video.VideoColumns.;
String sort = MediaStore.Video.VideoColumns._ID + " DESC";
Cursor myCursor = getActivity().managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, sort);
try
{
myCursor.moveToFirst();
Log.d("VIDEO_URI", intent.getDataString());
Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(
getActivity().getContentResolver(), myCursor.getLong(myCursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns._ID)),
MediaStore.Video.Thumbnails.MICRO_KIND,
(BitmapFactory.Options) null );
ImageView iv = (ImageView) getActivity().findViewById(R.id.attached_media_image);
//Log.d("IMAGE", curThumb.toString());
iv.setImageBitmap(bitmap);
}
catch (Exception e) {
// TODO: handle exception
Log.e("ERROR", e.toString());
}
我在我的LogCat中以下时,这是跑;
I get the following in my LogCat when this is ran;
03-13 12:05:14.740: D/VIDEO_URI(7269): content://media/external/video/media/474
但它的第四形象不设置任何东西,当我尝试运行Log.d(图像,curThumb.toString());行,被注释掉在这个例子中,它会引发空异常。
But it doesn't set the image of the iv to anything, and when I try to run the Log.d("IMAGE", curThumb.toString()); line, that is commented out in this example, it throws a null exception.
任何帮助将是非常美联社preciated谢谢你。
Any help would be much appreciated thank you.
推荐答案
缩略图生成不能保证,因为其产生的缩略图不能为某些视频codeCS这样做的部分成功。返回位图
将空
在这种情况下。
The thumbnail generation is not guaranteed to succeed since the part that generates thumbnails cannot do so for some video codecs. The returned Bitmap
will be null
in that case.
- 你检查是否
位!= NULL
? - 请你得到一个缩略图的视频在如画廊的应用程序?
- 什么是
curThumb
,我可以看到你的code中,没有定义。
- Have you checked if
bitmap != null
? - Do you get a thumbnail for the Video in e.g. the Gallery app?
- What is
curThumb
, I can see no definition of that in your code.
编辑:您的错误是你从缩略图表中没有视频的ID使用ID。 所有你需要做的是让位图是这样的:
Your error is that you use the ID from the thumbnails table not the id of the video. All you need to do is to get the Bitmap this way:
Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(
getActivity().getContentResolver(),
ContentUris.parseId(intent.getData()),
MediaStore.Video.Thumbnails.MICRO_KIND,
(BitmapFactory.Options) null );
API文档说:origId:有兴趣缩略图相关原始图片ID
Api Doc says: "origId: Original image id associated with thumbnail of interest."
这篇关于MediaStore.Video.Thumbnails.getThumbnail()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!