简体   繁体   中英

How do I use downloaded Google Play Store music in my android app?

I'm writing a simple app to detect and print all songs the user has on their device. However, the app cannot find any songs that have been downloaded/purchased through the Google Play Store. I can see the music if I go to the Play Music app, but my app omits those songs when it prints the song list. I tried the other solutions I could find on here, but I couldn't get any of them to work for me.

The commented out URI line makes the app crash when opened if I use it instead, though this seemed to be what other answers proposed. Here is the relevant part of the code:

public void getSongList() {
    ContentResolver musicResolver = getContentResolver();
    Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    //Uri musicUri = Uri.parse("content://com.google.android.music.MusicContent/audio");

    Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
    if(musicCursor!=null && musicCursor.moveToFirst()){
        //get columns
        int titleColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.TITLE);
        int idColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media._ID);
        int artistColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.ARTIST);
        //add songs to list
        do {
            long thisId = musicCursor.getLong(idColumn);
            String thisTitle = musicCursor.getString(titleColumn);
            String thisArtist = musicCursor.getString(artistColumn);
            songList.add(new Song(thisId, thisTitle, thisArtist));
        }
        while (musicCursor.moveToNext());
    }
    assert musicCursor != null;
    musicCursor.close();

}

Thank you, please keep in mind I'm fairly new to app development.

Google Play音乐不允许第三方应用程序通过任何API访问其音乐-您可以期望的唯一音乐是本地存储的音乐。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM