将所有捕获的视频在Android中作为列表获取

时间:2014-07-03 07:05:36

标签: android android-contentprovider android-gallery mediastore

我正在尝试使用以下代码在图库中显示所有视频,

 String[] proj = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
 videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj, null,null, null);
int count = videocursor.getCount();

但我总是得到count = 0,我在哪里弄错了?

我也试过

Cursor videocursor = managedQuery(MediaStore.Video.Media.INTERNAL_CONTENT_URI, proj, null, null, null);

1 个答案:

答案 0 :(得分:0)

这样做 -

String[] proj = { MediaStore.Video.Media.DATA,
                MediaStore.Video.Media._ID, MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.MIME_TYPE,
                MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.SIZE,};

 String orderBy = android.provider.MediaStore.Video.Media.TITLE;

 Cursor videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
               proj, null, null, orderBy);

要获得尺寸,您可以使用

 int count = videocursor.getCount();

编辑 managedQuery() is deprecated