public static void shuffleAll(final Context context) { Cursor cursor = SongLoader.makeSongCursor(context, null); final long[] mTrackList = SongLoader.getSongListForCursor(cursor); final int position = 0; if (mTrackList.length == 0 || mService == null) { return; } try { mService.setShuffleMode(MusicService.SHUFFLE_NORMAL); final long mCurrentId = mService.getAudioId(); final int mCurrentQueuePosition = getQueuePosition(); if (position != -1 && mCurrentQueuePosition == position && mCurrentId == mTrackList[position]) { final long[] mPlaylist = getQueue(); if (Arrays.equals(mTrackList, mPlaylist)) { mService.play(); return; } } mService.open(mTrackList, -1, -1, IdType.NA.mId); mService.play(); cursor.close(); cursor = null; } catch (final RemoteException ignored) { } }
public static final long[] getSongListForAlbum(final Context context, final long id) { final String[] projection = new String[] {BaseColumns._ID}; final String selection = MediaStore.Audio.AudioColumns.ALBUM_ID + "=" + id + " AND " + MediaStore.Audio.AudioColumns.IS_MUSIC + "=1"; Cursor cursor = context .getContentResolver() .query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, MediaStore.Audio.AudioColumns.TRACK + ", " + MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor != null) { final long[] mList = SongLoader.getSongListForCursor(cursor); cursor.close(); cursor = null; return mList; } return sEmptyList; }
@Override public boolean onQueryTextChange(final String newText) { if (newText.equals(queryString)) { return true; } queryString = newText; if (!queryString.trim().equals("")) { this.searchResults = new ArrayList(); List<Song> songList = SongLoader.searchSongs(this, queryString); List<Album> albumList = AlbumLoader.getAlbums(this, queryString); List<Artist> artistList = ArtistLoader.getArtists(this, queryString); if (!songList.isEmpty()) { searchResults.add("Songs"); } searchResults.addAll( (Collection) (songList.size() < 10 ? songList : songList.subList(0, 10))); if (!albumList.isEmpty()) { searchResults.add("Albums"); } searchResults.addAll( (Collection) (albumList.size() < 7 ? albumList : albumList.subList(0, 7))); if (!artistList.isEmpty()) { searchResults.add("Artists"); } searchResults.addAll( (Collection) (artistList.size() < 7 ? artistList : artistList.subList(0, 7))); } else { searchResults.clear(); adapter.updateSearchResults(searchResults); adapter.notifyDataSetChanged(); } adapter.updateSearchResults(searchResults); adapter.notifyDataSetChanged(); return true; }