Advice needed for manipulating the mediastore
I'm rather new to android programming and right now I'm playing with the media store for a personal test project. I've run into a couple double-edge problems..
I need to query the mediastore for a list of all music files, simple enough - but i need to restrict the results to certain folders only. I accomplished this (rather easily) using the SQL-*LIKE- where clauses and all's well on this aspect.
I now need a unique (if this were actually using SQL, I could simply use the DISTINCT modifier and be done with this) list of all artists. Now this is based off the songs in a given path. Therefore I cannot filter the list returned from querying the URI:MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, and adding in where clauses based off the file path as I did in the firs开发者_JAVA技巧t step.
So, what this leaves me with is using my initial query and getting a cursor back then stripping the dupes from the cursor (which is where i am now - too slow, especially with 1000+ songs) - based on a query of artists instead of songs, obviously.
Is is possible to override the actual query that fills the cursor, maybe? As in: override the query and filter how the data is initially put into the cursor (remove recursive entries) and return the proper cursor immediately? Content providers and how they were never built with a distinct function is beyond me, but whatever. Is the returned cursor from a URI query command filled in a manner that can be overridden or not? That's what I'm unclear of at the moment on this. I would like to be able to wrap the getContentResolver().query(xxx..)) command directly to remove the entries on cursor fill, if possible - i do async queries and using a single query statement (well, one for the artist query) would be great.
My other alternative thought is to just preload the data and manipulate my view's data by creating a new cursor based off the preloaded dataset (cursor) - which may be the way to go, and if so - would a cursor be the best way to store this data? Also worried about ram with larger libraries.
Maybe there's simply a way to do a DISTINCT query on the URI - I just do not know.
I've seen this question (or the ilk there-of) asked many times with no good answers that were meant for a URI as opposed to a SQL back-end.
Thank You all, appreciate the help.
Closing this, I've decided to use the mediastore just as it was intended. If it's on the device it should be listed in your mediaplayer.
If you look at any phone that is a media player (especially droid or iPhones, for example), they treat the device this way.
When technology advances and this becomes commonplace, i will adjust my content provider wrapper accordingly.
Simply put, can it be done - yes. Is it easy to do, not really. After putting in more thought, this is a phone - treat it as one. If anyone can prove why this "needs" to be implemented, I'm all ears.
Thanks, all!
精彩评论