Skip to content Skip to sidebar Skip to footer

How To Get Audio Path To Play Audio File?

This is my code that gets list of songs: List getsonglist() { List songlist = new ArrayList<>(); ContentResolver contentResolve

Solution 1:

You can get full path like this:

StringfullPath= cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));

So, Your function would be:

List<String> getsonglist() {

    List<String> songlist = newArrayList<>();
    ContentResolvercontentResolver= getContentResolver();
    Uriuri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    Cursorcursor= contentResolver.query(uri, null, null, null, null);
    if (cursor == null) {
        // query failed, handle error.
    } elseif (!cursor.moveToFirst()) {
        // no media on the device
    } else {
        do {

            StringfullPath= cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
            // ...process entry...
            Log.e("Full Path : ", fullPath);


            songlist.add(fullPath);
        } while (cursor.moveToNext());
    }


    return songlist;
}

Solution 2:

Post a Comment for "How To Get Audio Path To Play Audio File?"