Implement getSongByTypeId

This commit is contained in:
Adrian Ulrich 2015-08-06 11:19:15 +02:00
parent 1fd0a60fe1
commit a4ad16832c

View File

@ -405,6 +405,27 @@ public class MediaUtils {
sAllSongs = null;
}
/**
* Returns the first matching song (or NULL) of given type + id combination
*
* @param resolver A ContentResolver to use.
* @param type The MediaTye to query
* @param id The id of given type to query
*/
public static Song getSongByTypeId(ContentResolver resolver, int type, long id) {
Song song = new Song(-1);
QueryTask query = buildQuery(type, id, Song.FILLED_PROJECTION, null);
Cursor cursor = query.runQuery(resolver);
if (cursor != null) {
if (cursor.getCount() > 0) {
cursor.moveToPosition(0);
song.populate(cursor);
}
cursor.close();
}
return song.id == -1 ? null : song;
}
/**
* Returns a song randomly selected from all the songs in the Android
* MediaStore.