I am trying to query the Android MediaStore.Audio.Media database. I have a ‘playlist’, an ArrayList of strings which contains the paths of songs on a device (data column in the database). In the playlist, I only have some songs (of course, not all that are currently on the device), and I want the cursor to return artist, title and album id information from the database. The querying itself is not the problem, I just make the selection string and put the entries from the playlist as the selection arguments, and it works fine.
The problem is the order it returns the data in. When null is set as the ‘order by’ argument, the cursor returns the data in the ascending order. The songs in the playlist are in random order, and I need the info returned in that order.
I tried to query the database separately for each playlist entry, it works, gives me the info in the correct order, but it is, of course, a lot, and I mean a lot slower.
Is there any way to do this in a single query?
You can construct your own order by clause, where you include each of the songs in your list:
This assigns a number to each song. This number is used only in the order by clause to sort the results.