+
+ private static ContentValues[] sContentValuesCache = null;
+
+ /**
+ * @param ids The source array containing all the ids to be added to the playlist
+ * @param offset Where in the 'ids' array we start reading
+ * @param len How many items to copy during this pass
+ * @param base The play order offset to use for this pass
+ */
+ private static void makeInsertItems(long[] ids, int offset, int len, int base) {
+ // adjust 'len' if would extend beyond the end of the source array
+ if (offset + len > ids.length) {
+ len = ids.length - offset;
+ }
+ // allocate the ContentValues array, or reallocate if it is the wrong size
+ if (sContentValuesCache == null || sContentValuesCache.length != len) {
+ sContentValuesCache = new ContentValues[len];
+ }
+ // fill in the ContentValues array with the right values for this pass
+ for (int i = 0; i < len; i++) {
+ if (sContentValuesCache[i] == null) {
+ sContentValuesCache[i] = new ContentValues();
+ }
+
+ sContentValuesCache[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, base + offset + i);
+ sContentValuesCache[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, ids[offset + i]);
+ }
+ }