I'm writing a music player app and I'm wondering where should I look for the user's music files. I want to find all the songs that the Music app normally finds and I'm curious how that app finds the songs. Is there an enum variable for a specific folder? Just a recursive search of the sd card? I know on my phone's sd card there's a Music folder; is that how it is on every android device and should I just recursively search that folder? Or should I just ask the user to find the folder?
From the Home screen, tap Apps > Music Player . The Music Player application searches your phone for music files you copied into it, then builds a catalog of your music based on the information contained in each music file.
On your phone, you can usually find your files in the Files app . If you can't find the Files app, your device manufacturer might have a different app.
Typically, a computer has one location under which all music files are stored. This location is on your hard (or, more modernly, solid state) disk. Some operating systems have common locations for this. For instance, the default location in Windows is C:\[your username]\My Music\.
Downloaded files will be saved to the aptly named “Downloads” folder on your device.
You can find all music files from sdcard using below 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();
}
}
Android automatically scans all external SD cards for audio and indexes this data, see the MediaStore.Audio class for details. This allows you to query by Albums, Artists, Genres and Playlists. If you just want a list of media files can be found by querying the content provider MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With