@Override protected void onListItemClick(ListView l, View v, int position, long id) { // Dialog doesn't allow us to wait for a result, so we need to store // the info we need for when the dialog posts its result mQueryCursor.moveToPosition(position); if (mQueryCursor.isBeforeFirst() || mQueryCursor.isAfterLast()) { return; } String selectedType = mQueryCursor.getString( mQueryCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); if ("artist".equals(selectedType)) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album"); intent.putExtra("artist", Long.valueOf(id).toString()); startActivity(intent); } else if ("album".equals(selectedType)) { Intent intent = new Intent(Intent.ACTION_PICK); intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); intent.putExtra("album", Long.valueOf(id).toString()); startActivity(intent); } else if (position >= 0 && id >= 0) { int[] list = new int[] {(int) id}; MusicUtils.playAll(this, list, 0); } else { Log.e("QueryBrowser", "invalid position/id: " + position + "/" + id); } }
public void onServiceConnected(ComponentName name, IBinder service) { IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addDataScheme("file"); registerReceiver(mScanListener, f); Intent intent = getIntent(); if (intent.getAction().equals(Intent.ACTION_VIEW)) { // this is something we got from the search bar Uri uri = intent.getData(); String path = uri.toString(); if (path.startsWith("content://media/external/audio/media/")) { // This is a specific file String id = uri.getLastPathSegment(); int[] list = new int[] {Integer.valueOf(id)}; MusicUtils.playAll(this, list, 0); finish(); return; } else if (path.startsWith("content://media/external/audio/albums/")) { // This is an album, show the songs on it Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track"); i.putExtra("album", uri.getLastPathSegment()); startActivity(i); finish(); return; } else if (path.startsWith("content://media/external/audio/artists/")) { // This is an artist, show the albums for that artist Intent i = new Intent(Intent.ACTION_PICK); i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album"); i.putExtra("artist", uri.getLastPathSegment()); startActivity(i); finish(); return; } } mFilterString = intent.getStringExtra(SearchManager.QUERY); setContentView(R.layout.query_activity); mTrackList = getListView(); mTrackList.setTextFilterEnabled(true); if (mAdapter == null) { mAdapter = new QueryListAdapter( getApplication(), this, R.layout.track_list_item, null, // cursor new String[] {}, new int[] {}); setListAdapter(mAdapter); if (TextUtils.isEmpty(mFilterString)) { getQueryCursor(mAdapter.getQueryHandler(), null); } else { mTrackList.setFilterText(mFilterString); mFilterString = null; } } else { mAdapter.setActivity(this); setListAdapter(mAdapter); mQueryCursor = mAdapter.getCursor(); if (mQueryCursor != null) { init(mQueryCursor); } else { getQueryCursor(mAdapter.getQueryHandler(), mFilterString); } } }
private static void playAll(Context context, Cursor cursor, int position, boolean force_shuffle) { long[] list = getSongListForCursor(cursor); playAll(context, list, position, force_shuffle); }
public static void playAll(Context context, long[] list, int position) { playAll(context, list, position, false); }
public static void playAll(Context context, Cursor cursor, int position) { playAll(context, cursor, position, false); }
public static void playAll(Context context, Cursor cursor) { playAll(context, cursor, 0, false); }
public static void shuffleAll(Context context, Cursor cursor) { playAll(context, cursor, 0, true); }
public static void playPlaylist(Context context, long plid) { long[] list = getSongListForPlaylist(context, plid); if (list != null) { playAll(context, list, -1, false); } }