When we click on albums than it should display list of songs in album, I try like this but it displays all the songs in SD card
.
private OnItemClickListener musicgridlistener1 = new OnItemClickListener(){
public void onItemClick(AdapterView parent, View v, int position,long id)
{
System.gc();
album_column_index1 = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.AlbumColumns.ALBUM_ART);
musiccursor.moveToPosition(position);
MUSICfilename = musiccursor.getString(album_column_index1);
Log.i("=======this is file name of album========",""+musiccursor.getCount()+" "+MUSICfilename+" "+position);
String[] ablummusicproj = {MediaStore.Audio.Media.DATA,
MediaStore.Audio.AlbumColumns.ALBUM,
MediaStore.Audio.AlbumColumns.ARTIST,
MediaStore.Audio.Media.DISPLAY_NAME};
final String sortOrder = MediaStore.Audio.Media.ALBUM_KEY + " COLLATE LOCALIZED ASC";
//final String sortOrder= MediaStore.Audio.Media.ALBUM_KEY + " ASC, "
// + MediaStore.Audio.Media.TRACK + " ASC, "
// + MediaStore.Audio.Media.TITLE_KEY + " ASC";
Uri uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
musicAlbum = getBaseContext().getContentResolver().query(uri, ablummusicproj, null, null, sortOrder);
count = musicAlbum.getCount();
Log.i("++++++++++ value of album cursor is ",""+count);
gridmusic = (GridView) findViewById(R.id.gridmusic);
madAdapter_internal = new MusicalbumAdapter_internal(getApplicationContext());
gridmusic.setAdapter(madAdapter_internal);
gridmusic.setOnItemClickListener(musicgridlistener);
musiccursor=musicAlbum;
}
};
MusicalbumAdapter_internal
Class
public class MusicalbumAdapter_internal extends BaseAdapter {
private Context maContext;
public MusicalbumAdapter_internal(Context c) {
maContext = c;
Log.i("++++++++++++++++++", "this is context");
}
public int getCount() {
return count;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
TextView tv1 = new TextView(maContext.getApplicationContext());
String id = null;
if (convertView == null) {
music_column_index = musicAlbum.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DISPLAY_NAME);
musicAlbum.moveToPosition(position);
id = musicAlbum.getString(music_column_index);
//music_column_index = musiccursor
//.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE);
musicAlbum.moveToPosition(position);
//id += " Size(KB):" + musiccursor.getString(music_column_index);
tv1.setLayoutParams(new GridView.LayoutParams(100, 100));
tv1.setText(id);
} else
tv1 = (TextView) convertView;
return tv1;
}
}
you would have to store the album_key when u get the albums.
mediaStoreURI = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.ALBUM_KEY + "=?";
String[] projection = new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.ARTIST,
"strftime(\"%H-%M-%S\", (" + MediaStore.Audio.Media.DURATION + "/1000), \"unixepoch\") as time" };
String[] selectionArgs = new String[] { ((MediaContainerUSB) currentMediaObject).getUSBGroupingKey() };
String sortOrder = MediaStore.Audio.Media.TRACK;
the album_key is generated for ever album in the sdcard and stored in a different table as well.