7

可以通过查询找到播放列表名称MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI ,然后查看该MediaStore.Audio.PlaylistsColumns.NAME列。还有一个数据列,MediaStore.Audio.PlaylistsColumns._DATA,但它返回 null。

歌曲列表 ( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI/id) 似乎没有显示任何播放列表隶属关系。

4

3 回答 3

7

这是我的程序中的一些内容:

要点是您需要播放列表的 id 才能抓取歌曲。

基本上,您可以使用我的代码并将 where 语句更改为 .NAME +" = '"+name+"'",

private Cursor getPlaylists(String playlistId){
         Cursor cursor = null;

 String[] projection1 = {
        MediaStore.Audio.Playlists._ID,
        MediaStore.Audio.Playlists.NAME
     };

     cursor = this.managedQuery(
        MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
        projection1,
        MediaStore.Audio.Playlists._ID+ " = "+playlistId+"",
        null,
        null);
startManagingCursor(cursor);
cursor.moveToFirst();
   playlist_id = cursor.getString(0);
   playlist_id2 = cursor.getLong(0);

           if(playlist_id2 > 0){
           String[] projection = {
                   MediaStore.Audio.Playlists.Members.AUDIO_ID,
                   MediaStore.Audio.Playlists.Members.ARTIST,
                   MediaStore.Audio.Playlists.Members.TITLE,
                    MediaStore.Audio.Playlists.Members._ID



                };
           cursor = null;
                cursor = this.managedQuery(
                    MediaStore.Audio.Playlists.Members.getContentUri("external",playlist_id2 ),
                    projection,
                    MediaStore.Audio.Media.IS_MUSIC +" != 0 ",
                    null,
                    null);

           }
           cManager(cursor,2,1);
           return cursor;
       }
于 2010-07-05T03:56:35.023 回答
1

这是从播放列表中获取曲目的一种工作方式。基本上,它通过所有的播放列表查询循环游标,每次它获取成员(曲目)的 id 并使用该曲目的 id 我们可以获得其他数据,例如路径、艺术家、持续时间、专辑等。

 ContentResolver contentResolver = getContentResolver();
    Uri playListUri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistID); //playlistID is the _ID of the given playlist
    MediaMetadataRetriever mr = new MediaMetadataRetriever();
    Cursor cursor = contentResolver.query(playListUri, null, null, null, null);
    if(cursor != null)
    {
        if(cursor.moveToNext()) {
            do {
                String track_id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Playlists.Members.AUDIO_ID));
                Uri mediaContentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                String[] trackProjection = new String[]{MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.DATA};
                String selection = MediaStore.Audio.Media._ID + "=?";
                String[] selectionArgs = new String[]{"" + track_id};
                Cursor mediaCursor = contentResolver.query(mediaContentUri, trackProjection, selection, selectionArgs, null);
                if (mediaCursor != null) {
                    if (mediaCursor.getCount() >= 0) {
                        mediaCursor.moveToPosition(0);
                        String song_title = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
                        String song_artist = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
                        String song_album = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
                        String song_path = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.DATA));
                    }
                }
            } while (cursor.moveToNext());
        }

    }
于 2017-12-31T20:29:30.937 回答
0

这是从设备获取所有播放列表的方法

public ArrayList<String> getPlayList() {

            ArrayList<String> arrayList=new ArrayList<String>();

            String[] proj = {"*"};
            Uri tempPlaylistURI = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;

            // In the next line 'this' points to current Activity. 
            // If you want to use the same code in other java file then activity, 
            // then use an instance of any activity in place of 'this'. 

            Cursor playListCursor= activity.managedQuery(tempPlaylistURI, proj, null,null,null);

            if(playListCursor == null){
                System.out.println("Not having any Playlist on phone --------------");
                return arrayList;//don't have list on phone 
            } 

            System.gc();

            String playListName = null;

            System.out.println(">>>>>>>  CREATING AND DISPLAYING LIST OF ALL CREATED PLAYLIST  <<<<<<");

            for(int i = 0; i <playListCursor.getCount() ; i++)
            { 
                playListCursor.moveToPosition(i);
                playListName = playListCursor.getString(playListCursor.getColumnIndex("name"));
                System.out.println("> " + i + "  : " + playListName );
                arrayList.add(playListName);
            } 

            if(playListCursor != null)
                playListCursor.close();

            return arrayList;



        }
于 2015-06-09T04:14:40.170 回答