Location of Android music files?

I am writing a music player application and I wonder where I should look for user music files. I want to find all the songs that a music app usually finds, and I'm curious how this app finds songs. Is there an enum variable for a specific folder? Just a recursive search for an SD card? I know that there is a β€œMusic” folder on my sd phone card; is how it works on every Android device and should I just recursively look for this folder? Or should I just ask the user to find the folder?

+8
android
source share
2 answers

You can find all the music files from the SD card using the following function.

public void getAllSongsFromSDCARD() { String[] STAR = { "*" }; Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"; cursor = managedQuery(allsongsuri, STAR, selection, null, null); if (cursor != null) { if (cursor.moveToFirst()) { do { String song_name = cursor .getString(cursor .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME)); int song_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media._ID)); String fullpath = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.DATA)); String album_name = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.ALBUM)); int album_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media.ALBUM_ID)); String artist_name = cursor.getString(cursor .getColumnIndex(MediaStore.Audio.Media.ARTIST)); int artist_id = cursor.getInt(cursor .getColumnIndex(MediaStore.Audio.Media.ARTIST_ID)); } while (cursor.moveToNext()); } cursor.close(); } } 
+14
source share

Android automatically scans all external SD cards for audio and indexes this data, see MediaStore.Audio for details . This allows you to request albums, artists, genres and playlists. If you just want the list of media files to be found by requesting the content provider MediaStore.Audio.Media.EXTERNAL_CONTENT_URI .

+2
source share

All Articles