Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. private ArrayList < MediaFileInfo > audioList = new ArrayList < > ();
  2.  
  3. private void External() {
  4. try {
  5. String[] proj = {
  6. MediaStore.Audio.Media._ID,
  7. MediaStore.Audio.Media.TITLE,
  8. MediaStore.Audio.Media.ARTIST,
  9. MediaStore.Audio.Media.ALBUM
  10. }; // Can include more data for more details and check it.
  11.  
  12. String selection = MediaStore.Audio.Media.DURATION + ">=90000";
  13.  
  14. String[] selectionArgs = null;
  15.  
  16. String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
  17.  
  18. Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, selectionArgs, sortOrder);
  19.  
  20. if (audioCursor != null) {
  21. if (audioCursor.moveToFirst()) {
  22. do {
  23. int audioTitle = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
  24. int audioartist = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
  25. int audioalbum = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
  26. MediaFileInfo info = new MediaFileInfo();
  27. info.setTitle(audioCursor.getString(audioTitle));
  28. info.setAlbum(audioCursor.getString(audioalbum));
  29. info.setArtist(audioCursor.getString(audioartist));
  30. audioList.add(info);
  31. } while (audioCursor.moveToNext());
  32. }
  33. }
  34. audioCursor.close();
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38. }
  39. }
  40.  
  41. public class MediaFileInfo {
  42. private String title, artist, album;
  43.  
  44. public String getTitle() {
  45. return title;
  46. }
  47.  
  48. public void setTitle(String title) {
  49. this.title = title;
  50. }
  51.  
  52. public String getArtist() {
  53. return artist;
  54. }
  55.  
  56. public void setArtist(String artist) {
  57. this.artist = artist;
  58. }
  59.  
  60. public String getAlbum() {
  61. return album;
  62. }
  63.  
  64. public void setAlbum(String album) {
  65. this.album = album;
  66. }
  67. }
  68.  
  69. public class CustomeAdapter extends ArrayAdapter {
  70. private ArrayList < MediaFileInfo > audioList = new ArrayList < > ();
  71.  
  72. public CustomeAdapter(Context context, int resource) {
  73. super(context, resource);
  74. }
  75.  
  76. public CustomeAdapter(MainActivity context, ArrayList < MediaFileInfo > audioList) {
  77. super(context, R.layout.custome_list, audioList);
  78. }
  79.  
  80. @
  81. Override
  82. public View getView(int position, View convertView, ViewGroup parent) {
  83.  
  84. LayoutInflater imthebest = LayoutInflater.from(getContext());@
  85. SuppressLint("ViewHolder") View custome = imthebest.inflate(R.layout.custome_list, parent, false);
  86. MediaFileInfo item = audioList.get(0);
  87. String item1 = (String) getItem(position);
  88. TextView text1 = (TextView) custome.findViewById(R.id.textView);
  89. text1.setText(item1);
  90.  
  91.  
  92. return custome;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement