Hytod

FetchSong

Jul 5th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. private void fetchSong() {
  2. final String[] column = {MediaStore.Audio.Media.TITLE,MediaStore.Audio.Media.DURATION,MediaStore.Audio.Media.DATA};
  3. final String selection = MediaStore.Audio.Media.IS_MUSIC + "!= 0";
  4. Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,column,selection,null,null);
  5. while (cursor.moveToNext()) {
  6. Songs songData = new Songs(cursor.getString(0),cursor.getString(1),cursor.getString(2));
  7. if (new File(songData.getPath()).exists()){
  8. songsList.add(songData);
  9. }
  10. recyclerView.setHasFixedSize(true);
  11. recyclerView.setLayoutManager(new LinearLayoutManager(this));
  12. AdapterRecycler adapterRecycler = new AdapterRecycler(this,songsList);
  13. recyclerView.setAdapter(adapterRecycler);
  14. recyclerView.getAdapter().notifyDataSetChanged();
  15.  
  16. }
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment