5

I am writing a media player which can play audio and video files. Here i am using

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

    cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);

to query for the files. It's working fine. But it is giving only video files. So how can i get audio files and video files at a time.

saa
  • 1,538
  • 2
  • 17
  • 35
  • 1
    This may help (it is for images+video but you should be able to use it for audio+video as well): http://stackoverflow.com/questions/17664826/access-ordered-images-and-video-in-same-cursor – NigelK Jan 28 '14 at 10:44
  • Thanks NigelK.. this link would helpful to me.. – saa Jan 28 '14 at 10:48
  • Try this answer http://stackoverflow.com/a/17688221/2895571. I implemented it like this and it is working great. – pavle Aug 21 '16 at 22:25

1 Answers1

2

Based on this link Access ordered images and video in same Cursor correct answer is

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
        };

        String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
                 + MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO 
                 + " 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.
              );

        myCursor = cursorLoader.loadInBackground();
Community
  • 1
  • 1
saa
  • 1,538
  • 2
  • 17
  • 35