Get path of song from SD card in android
13,955
Get path and song Name from SD Card. You can find the path of the song from MediaStore.
The Media provider contains meta data for all available media on both internal and external storage devices.
private String[] STAR = { "*" };
public void ListAllSongs()
{
Cursor cursor;
Uri allsongsuri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
if (isSdPresent()) {
cursor = getContentResolver().query(allsongsuri, STAR, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String songname = 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 albumname = cursor.getString(cursor
.getColumnIndex(MediaStore.Audio.Media.ALBUM));
} while (cursor.moveToNext());
}
cursor.close();
}
}
}
public static boolean isSdPresent()
{
return android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
}
Author by
Zankhna
Enthusiastic Software Engineer interested in developing Mobile and Web application that can transform Visualization to the Reality.
Updated on June 04, 2022Comments
-
Zankhna almost 2 years
In my android application I want to fetch song from SD card but I am not able to get the path of that particular file.I am using android api level 7 which doesn't support following method.
Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_MUSIC);
I have also tried following code :
path = Environment.getExternalStorageDirectory();
but I don't know how to specify path of music file.Please suggest some solution.Thanx.
-
Chirag over 11 yearsMay I Know the Reason for Down Vote Please ?
-
Chirag over 11 yearsIts retrieve songs from sdcard ... From any folder
-
Lalit Poptani over 11 yearswhat is
MusicUtils
? simply copy and paste from your working projects? -
Chirag over 11 yearsBTW it is one class in which i declare isSdPresent() function .
-
Lalit Poptani over 11 yearsI would be better from next time if you just post the clear and answer expected from the user instead of complete wall of code.