From a4ad16832ce01116795572e047990e7b93586ccb Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Thu, 6 Aug 2015 11:19:15 +0200 Subject: [PATCH] Implement getSongByTypeId --- .../android/vanilla/MediaUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ch/blinkenlights/android/vanilla/MediaUtils.java b/src/ch/blinkenlights/android/vanilla/MediaUtils.java index ff963979..0c6b51af 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaUtils.java +++ b/src/ch/blinkenlights/android/vanilla/MediaUtils.java @@ -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.