Skip to content

Instantly share code, notes, and snippets.

@nikunjparadva
Forked from novoda/List music files
Created July 27, 2018 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikunjparadva/50a12dba5c72ed86cfed4a1c04d04554 to your computer and use it in GitHub Desktop.
Save nikunjparadva/50a12dba5c72ed86cfed4a1c04d04554 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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment