private boolean anySongsFound(Cursor cursor, Playlist playlist) { cursor.moveToFirst(); do { String songName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); if (playlist.containsSong(songName)) { return true; } } while (cursor.moveToNext()); return false; }
private int addToPlaylist(Cursor cursor, Uri insertUri, int order, Playlist playlist) { ContentResolver resolver = mContext.getContentResolver(); do { String songName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); if (playlist.containsSong(songName)) { long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); if (!playlistContains(id, insertUri)) { ContentValues values = new ContentValues(); values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, order++); values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, id); resolver.insert(insertUri, values); } } } while (cursor.moveToNext()); cursor.close(); return order; }