0

I create one application which record audio and store it in SD card. I done this part
successfully. Here is code for inserting Audio file to SD card.

protected void addRecordingToMediaLibrary() {
    ContentValues values = new ContentValues(4);
    long current = System.currentTimeMillis();
    values.put(MediaStore.Audio.Media.TITLE, "audio" + audiofile.getName());
    values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
    values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
    values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
    ContentResolver contentResolver = getContentResolver();

    Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    Uri newUri = contentResolver.insert(base, values);

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));
    Toast.makeText(this, "Added File " + newUri, Toast.LENGTH_LONG).show();
}

But now i want to show this Audio file in listView but i don't know how to do this.
Please give me any reference or hint.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

2 Answers2

0

Try using MediaStore from android.provider.MediaStore package, you can get the music files on the sdcard using this...

And this below tutorial from stackoverflow.com will be a great help...

Android MP3 file Filtering form sdcard

Edit : Removed blog url... Blog no more exits...

Community
  • 1
  • 1
Kumar Vivek Mitra
  • 33,294
  • 6
  • 48
  • 75
0

First of all extract all the mp3 files.

Use this method developed 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 getAllAudio() {
     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);

                 //Here you can create data base for recoring entries or may can create ArrayList of Class bean object having this fields for showing in ListView.


             } 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