ListView中显示从mediastore音频和视频 [英] ListView displaying audio and video from mediastore

查看:207
本文介绍了ListView中显示从mediastore音频和视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个显示从mediastore音频和视频列表。但是,我不知道如何创建这样一个查询 - 它甚至有可能获得为音频和视频在同一时间

I'm trying to create a list that shows both audio and video from the mediastore. However, I'm not sure how to create such a query - is it even possible to get information for both audio and video at the same time?

所以要查询的视频和音频我这样做:

So to query for video and audio I do this:

String[] projV = { MediaStore.Video.Media._ID,
            MediaStore.Video.Media.DATA,
            MediaStore.Video.Media.DISPLAY_NAME,
            MediaStore.Video.Media.DURATION,
            MediaStore.Video.Media.DATE_TAKEN };

Cursor videoCursor = getActivity().managedQuery(
                MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projV, null,
                null, null);

String[] projA = { MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA,
            MediaStore.Audio.Media.DISPLAY_NAME,
            MediaStore.Audio.Media.MIME_TYPE,
            MediaStore.Audio.Media.DURATION,
            MediaStore.Audio.Media.DATE_ADDED };
Cursor audioCursor = getActivity().managedQuery(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projA, null,
                null, null);

我看着使用 CursorJoiner MergeCursor ,但我不知道如何使用这些甚至某些其正确的解决方案。

I looked into using CursorJoiner or MergeCursor, but I'm not sure how to use these or even certain its the right solution.

所以我的问题是;有没有一种方法来构建与信息返回游标的音频和视频或者我需要更复杂的东西,如使用 CursorJoiner 或<$的mediaStore查询C $ C> MergeCursor 。

So my question is; Is there a way to construct a query for the mediaStore that returns a cursor with information for both audio and video or do I need to something more complex such as using CursorJoiner or MergeCursor.

正如我在一开始提到的那样,我的目标是让所有显示的音频和视频在mediastore名单 - 这是正确的做法还是我看着它从一个错误的角度。

As I mentioned at the start, my goal is to have a list displaying all the audio and video in the mediastore - is this the right approach or am I looking at it from a wrong angle?

感谢。

推荐答案

它通过使用MediaStore.Files用适当的选择条款可能从API-11。

It is possible from API-11 by using MediaStore.Files with an appropriate selection clause.

public Loader<Cursor> onCreateLoader(int id, Bundle bundle)
{
    final String PROJECTION[] = {FileColumns._ID, FileColumns.DATA, FileColumns.DATE_ADDED};
    final String ORDER = FileColumns.DATE_ADDED + " DESC";
    final String SELECTION =  "(" + FileColumns.MEDIA_TYPE + "=" + FileColumns.MEDIA_TYPE_VIDEO +") OR (" + FileColumns.MEDIA_TYPE + "=" + FileColumns.MEDIA_TYPE_IMAGE + ")";
    return new CursorLoader(getActivity(), Files.getContentUri("external"), PROJECTION, SELECTION, null, ORDER);
}

在这之前,你可以使用MergeCursor,如果你不关心排序顺序。看看MatrixCursor如果你需要管理的排序顺序。或者包裹在实现顺序逻辑的CursorWrapper你的光标。

Prior to that you can use a MergeCursor if you don't care about sort order. Look at MatrixCursor if you need to manage sort order. Alternatively wrap your cursors in a CursorWrapper that implements order logic.

这篇关于ListView中显示从mediastore音频和视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆