Account for sorting that takes place when querying random songs
This commit is contained in:
parent
d0ee5e8676
commit
605e14f930
@ -210,4 +210,15 @@ public class MediaUtils {
|
||||
list[i] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
public static void shuffle(Song[] list)
|
||||
{
|
||||
Random random = ContextApplication.getRandom();
|
||||
for (int i = list.length; --i != -1; ) {
|
||||
int j = random.nextInt(i + 1);
|
||||
Song tmp = list[j];
|
||||
list[j] = list[i];
|
||||
list[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,14 +216,14 @@ public class Song implements Parcelable {
|
||||
int end = Math.min(mAllSongsIdx + RANDOM_POPULATE_SIZE, mAllSongs.length);
|
||||
for (int i = mAllSongsIdx; i != end; ++i) {
|
||||
if (!first)
|
||||
selection.append(",");
|
||||
selection.append(',');
|
||||
|
||||
first = false;
|
||||
|
||||
selection.append(mAllSongs[i]);
|
||||
}
|
||||
|
||||
selection.append(")");
|
||||
selection.append(')');
|
||||
|
||||
Cursor cursor = resolver.query(media, FILLED_PROJECTION, selection.toString(), null, null);
|
||||
|
||||
@ -247,6 +247,9 @@ public class Song implements Parcelable {
|
||||
|
||||
cursor.close();
|
||||
|
||||
// The query will return sorted results; undo that
|
||||
MediaUtils.shuffle(mRandomCache);
|
||||
|
||||
mRandomCacheIdx = 0;
|
||||
mRandomCacheEnd = mAllSongsIdx + count;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user