【问题标题】:Querying Google Play Music database in Android在 Android 中查询 Google Play 音乐数据库
【发布时间】:2012-03-12 14:52:25
【问题描述】:

我正在尝试查询由“Google Play 音乐”应用创建的播放列表,但无法查询。我使用本地存储的内容创建了一个播放列表。我使用以下代码查询:

Cursor c = managedQuery(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
                                       new String[] {MediaStore.Audio.Playlists._ID,
                                                     MediaStore.Audio.Playlists.NAME
                                                    }, null, null, null);

这适用于 Winamp,但不适用于 Google Play 音乐。事实上,Winamp 不会显示使用 Google Play Music 创建的播放列表。但是,Google Play 音乐会显示使用 Winamp 创建的播放列表。我的猜测是 Google Play 音乐使用自己的数据库来存储播放列表,而其他播放器使用 Content Provider 和 uri MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI 来存储他们的播放列表。有没有办法获取使用 Google Play 音乐创建的播放列表?

【问题讨论】:

    标签: android android-contentprovider


    【解决方案1】:

    我知道这个帖子很旧,但我也一直在努力解决这个问题。

    Google Play 音乐在此非标准内容 URI 上公开其播放列表

    // list all playlists with their ID and Name
    Cursor cursor = getContentResolver().query(
        "content://com.google.android.music.MusicContent/playlists", 
        new String[] {"_id", "playlist_name" }, 
        null, null, null);
    

    Google Play 音乐内容提供商使用以下列名称

    • isAllLocal
    • playlist_owner_name
    • 有本地
    • 有远程
    • 有任何
    • KeepOnId
    • playlist_art_url
    • playlist_share_token
    • _id
    • _count
    • playlist_owner_profile_photo_url
    • keeponSongCount
    • 播放列表描述
    • 播放列表类型
    • playlist_id
    • keeponDownloadedSongCount
    • 播放列表名称

    如果没有这个非常有用的应用程序Content Provider Helper,我永远不会想到这一点

    【讨论】:

    • 能否请您发布一个轨道对象的列名?我刚刚安装了 Content Provider Helper,但那里没有列出“content://com.google.android.music.MusicContent/playlists”。
    • @Chrizzor,如果您为查询的第二个参数传递 null(而不是传递列列表),则结果将包含所有列。然后您可以检查游标的值(它有一个属性 mCursor 和一个属性 mColumns)以查看所有列名。我会在这里列出它们,但其中有 47 个!
    • 它只返回一条记录,即最后创建的播放列表。不返回所有记录。
    【解决方案2】:

    试试这个。

    String[] proj = {MediaStore.Audio.AudioColumns.TITLE,MediaStore.Audio.Media.ARTIST,MediaStore.Audio.Media._ID};
    Uri gMusicUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
    Cursor cursor = getApplicationContext().getContentResolver()
                .query(gMusicUri,
                        proj, null, null, null);
    

    【讨论】:

    • Thanx user1411426,是否有类似的方式来检索特定歌曲 ID 的专辑封面?
    【解决方案3】:

    Î 尝试查询 ContenProvider,就像您在启动 google Music 应用时在 Logcat 中看到的那样:

    getContentResolver().query(Uri.parse("content://com.google.android.music.MusicContent/playlists"), null, null, null, null);

    但我没有得到任何结果 :-( 可能我做错了什么,之前没有与 contentproviders 一起工作,或者 contentprovider 可能对其他应用程序不公开。

    【讨论】:

    • 这实际上对我有用,只需稍作改动。我没有使用“null”投影,而是使用 {MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists._ID}。我只需要播放列表的 ID 和名称。所以,这满足了我的需要。
    • 谢谢,不错的提示!有时间我会试试的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    相关资源
    最近更新 更多