android媒体库

获取到所有的视频信息:

ContentResolver contentResolver = getContentResolver();

String[]        projection1    =newString[]{MediaStore.Video.Media.DATA};

String[]        projection2    =newString[]{MediaStore.Video.Media.TITLE};

Cursor cursor1 = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,

projection1,

null,

null,

MediaStore.Video.Media.DEFAULT_SORT_ORDER);

Cursor cursor2 = contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,

projection2,

null,

null,

MediaStore.Video.Media.DEFAULT_SORT_ORDER);

cursor1.moveToFirst();

cursor2.moveToFirst();

intfileNum = cursor1.getCount();

String pic    =newString();

String picName =newString();

Log.d("HYceshi","initData: HYfileNum"+ fileNum);

for(intcounter =0; counter < fileNum; counter++) {

//            Log.d("tag", "---file is:" +

//                    cursor.getString(cursor

//                                            .getColumnIndex(MediaStore.Images.Media.DATA)));

pic = cursor1.getString(cursor1.getColumnIndex(MediaStore.Video.Media.DATA));

mVideos.add(pic);

cursor1.moveToNext();

}

for(intcounter =0; counter < fileNum; counter++) {

//            Log.d("tag", "---file is:" +

//                    cursor.getString(cursor

//                                            .getColumnIndex(MediaStore.Images.Media.DATA)));

picName = cursor2.getString(cursor2.getColumnIndex(MediaStore.Video.Media.TITLE));

mVideosName.add(picName);

cursor2.moveToNext();

}

cursor1.close();

cursor2.close();

获取到图片的信息:

ContentResolver contentResolver = getContentResolver();

String[]        projection1    =newString[]{MediaStore.Images.Media.DATA};

String[]        projection2    =newString[]{MediaStore.Images.Media.TITLE};

Cursor cursor1 = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,

projection1,

null,

null,

MediaStore.Images.Media.DEFAULT_SORT_ORDER);

Cursor cursor2 = contentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,

projection2,

null,

null,

MediaStore.Images.Media.DEFAULT_SORT_ORDER);

cursor1.moveToFirst();

cursor2.moveToFirst();

intfileNum = cursor1.getCount();

String pic    =newString();

String picName =newString();

Log.d("HYceshi","initData: HYfileNum"+ fileNum);

for(intcounter =0; counter < fileNum; counter++) {

//            Log.d("tag", "---file is:" +

//                    cursor.getString(cursor

//                                            .getColumnIndex(MediaStore.Images.Media.DATA)));

pic = cursor1.getString(cursor1.getColumnIndex(MediaStore.Images.Media.DATA));

mPics.add(pic);

cursor1.moveToNext();

}

for(intcounter =0; counter < fileNum; counter++) {

//            Log.d("tag", "---file is:" +

//                    cursor.getString(cursor

//                                            .getColumnIndex(MediaStore.Images.Media.DATA)));

picName = cursor2.getString(cursor2.getColumnIndex(MediaStore.Images.Media.TITLE));

mPicsName.add(picName);

cursor2.moveToNext();

}

cursor1.close();

cursor2.close();

你可能感兴趣的:(android媒体库)