I am wanting to query the members of a given playlist. I have the correct playlist id, and want to use a managedQuery() to look at the playlist members in question.
What I have is this:
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, null);
I don't know what the volume argument needs to be. I've tried this:
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI.toString()
for the "volume" argument.
That gives me back a valid content URI that looks like:
content://media/external/audio/playlists/2/members
However, my cursor comes back null. I probably am way off base -- I know what I want to do is very simple.
The String "external" works as the volume in MediaStore.Audio.Playlists.Members.getContentUri(volume, playlistId)
This activity prints the songs on an Android, and the playlists, and their contents.
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,null,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, STAR, null,null,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, STAR, null, null, 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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With