Don't crash when failing to query a saved song

This commit is contained in:
Christopher Eby committed 2011-09-27 00:26:42 -05:00
1 parent d17df425cd
commit cd935206e4
1 file changed
+16 -14
+16 -14
View File
@@ -220,21 +220,23 @@ public final class SongTimeline {
Cursor cursor = resolver.query(media, Song.FILLED_PROJECTION, selection.toString(), null, "_id");
if (cursor != null) {
cursor.moveToNext();
if (cursor.getCount() != 0) {
cursor.moveToNext();
// Loop through timeline entries, looking for a row
// that matches the id. One row may match multiple
// entries.
Iterator<Song> it = songs.iterator();
while (it.hasNext()) {
Song e = it.next();
while (cursor.getLong(0) < e.id)
cursor.moveToNext();
if (cursor.getLong(0) == e.id)
e.populate(cursor);
else
// We weren't able to query this song.
it.remove();
// Loop through timeline entries, looking for a row
// that matches the id. One row may match multiple
// entries.
Iterator<Song> it = songs.iterator();
while (it.hasNext()) {
Song e = it.next();
while (cursor.getLong(0) < e.id && !cursor.isLast())
cursor.moveToNext();
if (cursor.getLong(0) == e.id)
e.populate(cursor);
else
// We weren't able to query this song.
it.remove();
}
}
cursor.close();