Optimize isSongAvailable()

This commit is contained in:
Christopher Eby 2011-08-27 18:07:22 -05:00
parent 13f80aaca4
commit 444b7f588b

View File

@ -130,10 +130,12 @@ public class Song implements Parcelable {
ContentResolver resolver = ContextApplication.getContext().getContentResolver(); ContentResolver resolver = ContextApplication.getContext().getContentResolver();
Uri media = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Uri media = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0"; String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor cursor = resolver.query(media, EMPTY_PROJECTION, selection, null, null); Cursor cursor = resolver.query(media, new String[]{"count(_id)"}, selection, null, null);
mSongCount = cursor == null ? 0 : cursor.getCount(); if (cursor != null) {
if (cursor != null) cursor.moveToFirst();
mSongCount = cursor.getInt(0);
cursor.close(); cursor.close();
}
} }
return mSongCount != 0; return mSongCount != 0;