在相同的游标访问有序的图像和视频 [英] Access ordered images and video in same Cursor
问题描述
我使用了 android.content.CursorLoader
类来创建两个光标
对象来访问存储介质上我的应用程序的设备的用户。我想给用户自己存储的图像和视频,其中价值从Android画廊的应用程序p $ pserves秩序的网格视图。
目前我使用的是一个光标
访问图像,一个用于访问视频。用这种方法,所有图像precede所有视频(即它们属于两个不同的群体)。有没有办法从相同的光标
访问图像和视频两者兼而有之?如果没有,有没有更好的方式来在设备上访问这些媒体?
有关引用,这里是code我使用的:
有关图片:
CursorLoader cursorLoader =新CursorLoader(
mContext,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
IMAGE_PROJECTION,
空值,
空值,
MediaStore.Images.Media._ID +递减
);
mImageCursor = cursorLoader.loadInBackground();
和视频:
CursorLoader cursorLoader =新CursorLoader(
mContext,
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
VIDEO_PROJECTION,
空值,
空值,
MediaStore.Video.Media._ID +递减
);
mVideoCursor = cursorLoader.loadInBackground();
在大量的研究,并与源$ C $ C玩弄,我终于有点更熟悉Android的文件系统。为了得到一个光标
可访问有关两个图片
和视频$ C信息$ C>我用下面的:
//获取相关列以备后用。
的String []投影= {
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MIME_TYPE,
MediaStore.Files.FileColumns.TITLE
};
//返回唯一的视频和图像元数据。
串选择= MediaStore.Files.FileColumns.MEDIA_TYPE +=
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
+或
+ MediaStore.Files.FileColumns.MEDIA_TYPE +=
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
乌里queryUri = MediaStore.Files.getContentUri(外部);
CursorLoader cursorLoader =新CursorLoader(
本,
queryUri,
投影,
选择,
空,//选择的args(无)。
MediaStore.Files.FileColumns.DATE_ADDED +降序//排序顺序。
);
光标光标= cursorLoader.loadInBackground();
I'm using the android.content.CursorLoader
class to create two Cursor
objects to access media stored on the user of my app's device. I'd like to give the user a grid view of their stored images and video which preserves order from the Android Gallery app.
Currently I'm using one Cursor
to access Images and one to access Video. With this approach, all images precede all videos (i.e. they are in two separate groups). Is there a way to access both Images and Video from the same Cursor
? If not, is there a better way to access these media on the device?
For reference, here is the code I am using:
For Images:
CursorLoader cursorLoader = new CursorLoader(
mContext,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
IMAGE_PROJECTION,
null,
null,
MediaStore.Images.Media._ID + " desc"
);
mImageCursor = cursorLoader.loadInBackground();
And Video:
CursorLoader cursorLoader = new CursorLoader(
mContext,
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
VIDEO_PROJECTION,
null,
null,
MediaStore.Video.Media._ID + " desc"
);
mVideoCursor = cursorLoader.loadInBackground();
After lots of research and playing around with source code, I'm finally a bit more familiar with the Android filesystem. To get a single Cursor
which can access information about both Images
and Video
I used the following:
// Get relevant columns for use later.
String[] projection = {
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATA,
MediaStore.Files.FileColumns.DATE_ADDED,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MIME_TYPE,
MediaStore.Files.FileColumns.TITLE
};
// Return only video and image metadata.
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
+ " OR "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "="
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
Uri queryUri = MediaStore.Files.getContentUri("external");
CursorLoader cursorLoader = new CursorLoader(
this,
queryUri,
projection,
selection,
null, // Selection args (none).
MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
);
Cursor cursor = cursorLoader.loadInBackground();
这篇关于在相同的游标访问有序的图像和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!