android - Getting AUDIO_ID when querying the whole Media Store -


after knowing difference between _id , audio_id (what difference between _id , audio_id column?), i'm changing query use audio_id instead, got problem here.

here's code snippet intended query audio files in external storage , make "music" instances each of them embedded audio_id.

uri uri = android.provider.mediastore.audio.media.external_content_uri; cursor cur = mcontentresolver.query(uri, null,      mediastore.audio.media.is_music + " = 1", null, null);  int artistcolumn = cur.getcolumnindex(mediastore.audio.media.artist); int titlecolumn = cur.getcolumnindex(mediastore.audio.media.title); int idcolumn = cur.getcolumnindex(mediastore.audio.playlists.members.audio_id);  // of above columns return right integers,  // except idcolumn returns -1 making further code below throws exception  do{     music music = new music(); // it's music class     music.setartist( cur.getstring(artistcolumn) );     music.settitle( cur.getstring(titlecolumn) );     music.setid( cur.getlong(idcolumn) ); // error here, because idcolumn = -1 (column not found)      // ...... } while (cur.movetonext()) 

why can't audio_id column when querying mediastore.audio.media.external_content_uri? there way retrieve it? (any workarounds appreciated)

i need since app needs absolute reference audio files explained in answer comment here -> https://stackoverflow.com/a/17648131/670623

thanks :)

edit

i found question solution close i'm searching (it can audio_id), it's intended list audio files certain playlist. while concern querying whole mediastore audio_ids regardless playlist are.

given android music playlist name, how can 1 find songs in playlist?

i did tests mediastore.audio.media , mediastore.audio.playlists.members databases. have created small playlist same song contained several times , database looks this:

playlist database

+---------------------------+ |_id | audio_id | songtitle | +---------------------------+ |273 | 2913     | alone     | |274 | 1487     | baby      | |275 | 2913     | alone     | |276 | 2913     | alone     | |277 | 1487     | baby      | |278 | 2648     | battery   | +---------------------------+ 

as expected _id locally unique identifier within playlist. of course there several other playlists own _id identifiers. audio_id can't used identify specific row in database because same song can appear multiple times in single playlist.

audio_id globally unique identifier same song.

now let's @ mediastore.audio.media database. in here, songs known mediastore system stored. (this excerpt)

media database

+-------------------+ |_id  | songtitle   | +-------------------+ |      ....         | |1487 | baby        | |      ....         | |2648 | battery     | |     ....          | |2913 | alone       | |     ....          | +-------------------+ 

it seems _id identifier in mediastore.audio.media used globally unique identifier called audio_id in mediastore.audio.playlists.members databases.

this seems strange @ first, every song has contained in mediastore.audio.media , can appear there once. , since there 1 such database, _id in database should globally unique each song.


Comments