Skip to content

Instantly share code, notes, and snippets.

@novoda
Created April 21, 2010 23:01
Show Gist options
  • Save novoda/374533 to your computer and use it in GitHub Desktop.
Save novoda/374533 to your computer and use it in GitHub Desktop.
Android: List all music files
//Retrieve a list of Music files currently listed in the Media store DB via URI.
//Some audio may be explicitly marked as not being music
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION
};
cursor = this.managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null);
private List<String> songs = new ArrayList<String>();
while(cursor.moveToNext()){
songs.add(cursor.getString(0) + "||" + cursor.getString(1) + "||" + cursor.getString(2) + "||" + cursor.getString(3) + "||" + cursor.getString(4) + "||" + cursor.getString(5));
}
@cinder92
Copy link

is not getting mp4 files

@KunalBhorodiya
Copy link

KunalBhorodiya commented Sep 26, 2018

As i scroll it fast it gives me less song list. but if i scroll it slow it gives me more song.

@FirstVoyager
Copy link

Thank you very much
I was looking for a list of songs for a few days
And I found it here.
Thank You

@CodeBoy722
Copy link

any body knows how this is done on android Q , i have tried and this does not work and MediaStore.Audio.Media.DATA is deprecated too

@dikshu-py
Copy link

How to get all mp3 files from a specific folder

@shakeelAhmad123
Copy link

how to list all audio files from storage specific folder and show in recyclerview in android

@CodeBoy722
Copy link

Hello every one, i recently created and Android class library for actions concerning the MediaStore and acces to media content on a device, It Called MediaFacer and it also support android 10 and 11 MediaStore changes. and it very easy to use

@shakeelAhmad123 what you are asking for can be done in few lines of code with MediaFacer
read this Medium article to understand how it works https://android.jlelse.eu/handling-media-files-with-mediafacer-library-for-android-cd9d2ca0dc68?source=friends_link&sk=02eb8a77e0d9f1958045a39550f0e3a0

MediaFacer on GitHub https://github.com/CodeBoy722/MediaFacer

@Hamza417
Copy link

Hamza417 commented Dec 7, 2020

Hello every one, i recently created and Android class library for actions concerning the MediaStore and acces to media content on a device, It Called MediaFacer and it also support android 10 and 11 MediaStore changes. and it very easy to use

@shakeelAhmad123 what you are asking for can be done in few lines of code with MediaFacer
read this Medium article to understand how it works https://android.jlelse.eu/handling-media-files-with-mediafacer-library-for-android-cd9d2ca0dc68?source=friends_link&sk=02eb8a77e0d9f1958045a39550f0e3a0

MediaFacer on GitHub https://github.com/CodeBoy722/MediaFacer

Thank you so much for this amazing work, this part is making me cry for months and your library helped me learn a lot, I really appreciate your work :)

@faisalM008
Copy link

Thtat greate Thank you so much

@OtienoSamwel
Copy link

Is using a content provider the right way to go about it? That is if you want to go from scratch?

@thuanpham582002
Copy link

Hello every one, i recently created and Android class library for actions concerning the MediaStore and acces to media content on a device, It Called MediaFacer and it also support android 10 and 11 MediaStore changes. and it very easy to use

@shakeelAhmad123 what you are asking for can be done in few lines of code with MediaFacer read this Medium article to understand how it works android.jlelse.eu/handling-media-files-with-mediafacer-library-for-android-cd9d2ca0dc68?source=friends_link&sk=02eb8a77e0d9f1958045a39550f0e3a0

MediaFacer on GitHub github.com/CodeBoy722/MediaFacer

Thank you so much for this amazing work, this part is making me cry for months and your library helped me learn a lot <3

@chiragdhunna
Copy link

How to use it?

  1. You have to add a listview in xml
  2. Then name that listview and add findviewbyid method to it
  3. Then use a adaptor whichever you can use
  4. For eg : ArrayAdapter ad = new ArrayAdapter(this,android.R.id.layout.simple_list_view_1,songs);
    listview.setadapter(ad);

then it will list those .mp3 files in your activity!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment