Question

I want to get all the musics which are not in a given playlist using CursorLoader. Is it possible?

We can get all the music in a list using the following code

loader = new CursorLoader(context, MediaStore.Audio.Playlists.Members
                .getContentUri("external", playlistID), proj,
                MediaStore.Audio.Media.IS_MUSIC + " != 0 ", null, ORDER_BY);

But I need to do the opposite, which is to get all the music that are not in a given playlist. How can I do that?

Was it helpful?

Solution

I can't help you fix your LowAcceptRateException - that's a critical failure around here that's likely to interfere with questions being answered in the long run - but if you do not mind doing stuff that is hard to maintain and abuses internal functionality in the MediaProvider you can do like this to get songs that are not in a (specific) playlist.

loader = new CursorLoader(context, Audio.Media.EXTERNAL_CONTENT_URI, proj,
            Media._ID + " NOT IN (SELECT audio_id FROM audio_playlists_map WHERE playlist_id=?) AND " + 
            MediaStore.Audio.Media.IS_MUSIC + " != 0 ", 
            new String[]{String.valueOf(playlistID}, ORDER_BY);

Edit: Corrected audio_playlist_map to audio_playlists_map

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top