Get Genre_id And Audio_id From Audio_genres_map From Mediastore
I want to retrieve whole audio_genres_map table from mediastore in one query. I have all the audio info and genre info but the missing piece is the mapping. I am able to do it in m
Solution 1:
managed to solve this using following query
String[] genresProjection = {
Audio.Genres.Members.AUDIO_ID,
Audio.Genres.Members.GENRE_ID
};
context.getContentResolver().query(Uri.parse("content://media/external/audio/genres/all/members"), genresProjection, null, null, null);
Solution 2:
Or to retrieve all genres using MediaStore.Audio
public Cursor getGenrecursor(Context context) {
ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Audio.Genres.getContentUri("external");
String genre = MediaStore.Audio.Genres.NAME;
final String[] columns = { "_id", genre };
return cr.query(uri, columns, null, null, null);
}
Solution 3:
and to expand your question, using the genre_id to bring back further details
public Cursor getgenre_TrackCursor(Context context, long genreID) {
final String track_id = MediaStore.Audio.Genres.Members._ID;
final String track_no = MediaStore.Audio.Genres.Members.TRACK;
final String track_name = MediaStore.Audio.Genres.Members.TITLE;
final String artist = MediaStore.Audio.Genres.Members.ARTIST;
final String duration = MediaStore.Audio.Genres.Members.DURATION;
final String album = MediaStore.Audio.Genres.Members.ALBUM;
final String composer = MediaStore.Audio.Genres.Members.COMPOSER;
final String year = MediaStore.Audio.Genres.Members.YEAR;
final String path = MediaStore.Audio.Genres.Members.DATA;
final ContentResolver resolve = context.getContentResolver();
Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external",
genreID);
final String[] columns = { track_id, track_no, artist, track_name,
album, duration, year };
return resolve.query(uri, columns, null, null, null);
}
Post a Comment for "Get Genre_id And Audio_id From Audio_genres_map From Mediastore"