Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all audio, video files

Tags:

android

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.

like image 912
saa Avatar asked Nov 01 '22 06:11

saa


1 Answers

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();
like image 154
saa Avatar answered Nov 12 '22 15:11

saa