[英]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. 但是,该应用程序找不到通过Google Play商店下载/购买的任何歌曲。 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. 如果我转到Play音乐应用,可以看到音乐,但是在打印歌曲列表时,我的应用会忽略这些歌曲。 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. 如果我改为使用注释掉的URI行,则在打开应用程序时该应用程序将崩溃,尽管这似乎是其他答案的建议。 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访问其音乐-您可以期望的唯一音乐是本地存储的音乐。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.