如何获取视频的唯一ID

时间:2011-01-28 06:20:22

标签: android

在我的应用程序中,我试图在一个Activity的列表视图中显示视频列表,我试图在另一个Activity中显示所选视频的缩略图,因为我得到了一个用于在ImageView

中显示缩略图的代码
iv = (ImageView)findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setImageBitmap(curThumb);

仅当我在

中指定id的整数值时才会显示缩略图
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id, MediaStore.Video.Thumbnails.MICRO_KIND, options);

但我想要的是获取所选视频的id值,以便我可以根据需要显示新的Activity

感谢。

2 个答案:

答案 0 :(得分:0)


String[] projection = { BaseColumns._ID, MediaColumns.DATA };               
Cursor cursor = managedQuery(data, projection, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
int id = cursor.getInt(columnIndex);

此代码将为您提供帮助,“数据”是所选视频的uri

答案 1 :(得分:0)

试一试:详情Click Here

int id = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID));
String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,
MediaStore.Video.Thumbnails.VIDEO_ID};
Cursor thumbCursor = managedQuery(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + "=" + id, null, null);
if (thumbCursor.moveToFirst()) {
       Log.v("VideoGallery",thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
}