1

I use

Uri deviceMusic = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String sortOrder = MediaStore.Audio.Media.DISPLAY_NAME;
Cursor cursor = this.getContentResolver().query(deviceMusic, null,
            selection, null, sortOrder);

to quer music from device,

but it can not find music in "extSdCard".

So, How to query music when the device have mnt/sdcrad and "extSdCard" in the same time?

Edit: Sorry, what i mean is i can get music in mnt/sdcard

but i can not get music in mnt/extSdCard

extSdCard is a real sdcard which can remove by hand on the device

picture: enter link description here

user1531240
  • 875
  • 1
  • 11
  • 20

1 Answers1

2

Use this method develop3ed by me.... for getting mp3 files of sd card

For getting detailed I also have asked an question Observing changes in android content observer for Audio.Media.EXTERNAL_CONTENT_URI

This code will work for both mnt/sdcrad and extSdCard

In this code I have retrieved

  1. File Name

  2. File Path

  3. Time

  4. Duration

for each mp3 file. There are so many fields that you can retrieve refer this http://developer.android.com/reference/android/provider/MediaStore.Audio.AudioColumns.html

      private void showAllAudio() {
     Cursor mCursor = null;

     try {
         mCursor = context.getContentResolver().query(
             Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, "_id");

         System.out.println("Cursor count is " + mCursor.getCount());

         if (mCursor.getCount() != 0) {

             do {


                 long date = mCursor.getLong(mCursor
                     .getColumnIndexOrThrow(Audio.Media.DATE_ADDED));

                 String Duration = mCursor.getString(mCursor
                     .getColumnIndexOrThrow(Audio.Media.DURATION));
                 String DISPLAY_NAME = mCursor.getString(mCursor
                     .getColumnIndexOrThrow(Audio.Media.DISPLAY_NAME));
                 String DATA = mCursor.getString(mCursor
                     .getColumnIndexOrThrow(Audio.Media.DATA));
                 double TIME_STAMP = mCursor.getInt(mCursor
                     .getColumnIndexOrThrow(Audio.Media.DATE_ADDED));


                 System.out.println("Name:" + DISPLAY_NAME);
                 System.out.println("data " + DATA);
                 System.out.println("time " + TIME_STAMP);
                 System.out.println("time " + Duration);
             } while (mCursor.moveToNext());

         }
     } catch (Exception e) {
         e.printStackTrace();
     } finally {
         if (mCursor != null) {
             mCursor.close();
             mCursor = null;
         }
     }

 }
 }
Community
  • 1
  • 1
Nikhil Agrawal
  • 26,128
  • 21
  • 90
  • 126