Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. private void getMusic() {
  2. ContentResolver contentResolver = getContentResolver();
  3.  
  4. Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
  5. Cursor songCursor = contentResolver.query(songUri, null, null, null, null);
  6.  
  7. if (songCursor != null && songCursor.moveToFirst()) {
  8. int songTitle = songCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
  9. int songArtist = songCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
  10.  
  11. do {
  12. String currentTitle = songCursor.getString(songTitle);
  13. String currentArtist = songCursor.getString(songArtist);
  14.  
  15. arrayList.add("Title: " + currentTitle + "n" + "Artist: " + currentArtist);
  16. } while (songCursor.moveToNext());
  17.  
  18. }
  19.  
  20. }
  21.  
  22. private void getMusic() {
  23. ContentResolver contentResolver = getContentResolver();
  24.  
  25. Uri songUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
  26. Cursor songCursor = contentResolver.query(songUri, null, null, null, null);
  27.  
  28. if (songCursor != null && songCursor.moveToFirst()) {
  29. int songTitle = songCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
  30. int songArtist = songCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
  31.  
  32. do {
  33. String currentTitle = songCursor.getString(songTitle);
  34. String currentArtist = songCursor.getString(songArtist);
  35.  
  36. arrayList.add("Title: " + currentTitle);
  37. } while (songCursor.moveToNext());
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement