android – MediaStore.Audio.Playlists.Members.getContentUri引用的String的“volumeName”参数是什么?

前端之家收集整理的这篇文章主要介绍了android – MediaStore.Audio.Playlists.Members.getContentUri引用的String的“volumeName”参数是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想查询给定播放列表的成员.我有正确的播放列表ID,并且想要使用managedQuery()来查看有问题的播放列表成员.

我所拥有的是:

private String [] columns = { 
     MediaStore.Audio.Playlists.Members.PLAYLIST_ID,MediaStore.Audio.Playlists.Members.TITLE,};
Uri membersUri = MediaStore.Audio.Playlists.Members.getContentUri(volume,playlistId);
Cursor tCursor = managedQuery(membersUri,columns,null,null);

我不知道音量参数是什么.我试过这个:
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI.toString()为“volume”参数.

这给我一个有效的内容URI,看起来像:

content://media/external/audio/playlists/2/members

但是,我的光标返回null.我可能离开了基地 – 我知道我想做的很简单.

解决方法

字符串“external”用作MediaStore.Audio.Playlists.Members.getContentUri(volume,playlistId)中的卷

此活动将打印Android上的歌曲,播放列表及其内容.

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;

public class PlaylistActivity extends Activity {
    private final String [] STAR= {"*"};
    private final String TAG= "list";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        Log.i(TAG,"All the titles");
        Uri allaudio_uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        Cursor ca= managedQuery(allaudio_uri,STAR,null);
        for(ca.moveToFirst(); !ca.isAfterLast(); ca.moveToNext()){
            if(ca.isFirst()){   // print all the fields of the first song
                for(int k= 0; k<ca.getColumnCount(); k++)
                    Log.i(TAG,"  "+ca.getColumnName(k)+"="+ca.getString(k));
            }else{              // but just the titles of the res
                Log.i(TAG,ca.getString(ca.getColumnIndex("title")));
            }
        }
        Log.i(TAG,"--------------------------");
        Log.i(TAG,"All the playlists");
        Uri playlist_uri= MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;    
        Cursor cursor= managedQuery(playlist_uri,null);
        cursor.moveToFirst();
        for(int r= 0; r<cursor.getCount(); r++,cursor.moveToNext()){
            Log.i(TAG,"-----");
            Log.i(TAG,"Playlist " + cursor.getString(cursor.getColumnIndex("name")));
            for(int k= 0; k<cursor.getColumnCount(); k++)           
                Log.i(TAG,cursor.getColumnName(k)+"="+cursor.getString(k));

            // the members of this playlist
            int id= cursor.getInt(0);
            Uri membersUri = MediaStore.Audio.Playlists.Members.getContentUri("external",id);
            Cursor membersCursor = managedQuery(membersUri,null);
            membersCursor.moveToFirst();
            for(int s= 0; s<membersCursor.getCount(); s++,membersCursor.moveToNext())
                Log.i(TAG,"  "+membersCursor.getString(membersCursor.getColumnIndex("title")));
            membersCursor.close();
        }
        cursor.close();
    }
}
原文链接:https://www.f2er.com/android/313017.html

猜你在找的Android相关文章