1

Context

I'm learning Android app development and to learn I thought I would build a music library app. I intend for the app initially to show songs from other apps on the device (then eventually moving onto playback). For example, on my phone there is music in both One Drive and Play Music. I would like to query both of their libraries.

What I've Tried

I uploaded a couple of songs (.mp3 & .flac) into the the sdcard/Music folder on the device. I ensured Play Music and Groove had populated music libraries.

public SongReader GetSongs()
{
    Cursor cursor = activity
        .getContentResolver()
        .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.AudioColumns.DISPLAY_NAME + " ASC");
    return new SongReader(cursor);
}

SongReader is a custom class designed to iterate over a Cursor and read custom Song objects.

Problem

No songs are returned from the query call. Using the debugger and evaluating cursor.getCount() returns 0 and cursor.getColumns() returns 27 values.

Question

How can the music libraries of other apps be queried?

(Optional) Why did the couple of songs I uploaded to the device not get returned in the query response?

(Optional) Is there any way, I can detect any app installed on the device that "exposes" a media library?

TomTom
  • 301
  • 5
  • 16
  • 1
    This might be a permission issue. Try adding `READ_EXTERNAL_STORAGE` to the app manifest. I don't think it'll query Play Music or One Drive, but it should at least find the files you added to sdcard/Music. – Corey Ogburn Jul 17 '18 at 20:42
  • I have in the AndroidManifest.xml file, so I'm a bit confused why it's not detecting them. – TomTom Jul 17 '18 at 21:18
  • 1
    Have you run a media scan? Restart your device or [do it programmatically](https://stackoverflow.com/questions/13270789/how-to-run-media-scanner-in-android) – Corey Ogburn Jul 17 '18 at 22:02
  • I'll implement a media scan button in the menu of the app tomorrow. Hopefully that works. I'm also interested in querying media from Play Music, maybe it exposes an api? – TomTom Jul 17 '18 at 22:16
  • I restarted the device today and it found the songs and shows them in the list! – TomTom Jul 18 '18 at 20:19

0 Answers0