Advertisement
paranid5

LoadExternalStorage

Jun 5th, 2021
1,570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.17 KB | None | 0 0
  1. private fun loadStorageData() {
  2.         val selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"
  3.  
  4.         val projection = arrayOf(
  5.             MediaStore.Audio.Media._ID,
  6.             MediaStore.Audio.Media.TITLE,
  7.             MediaStore.Audio.Media.ARTIST,
  8.             MediaStore.Audio.Media.ALBUM,
  9.             MediaStore.Audio.Media.DATA,
  10.             MediaStore.Audio.Media.DURATION
  11.         )
  12.  
  13.         contentResolver.query(
  14.             MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
  15.             projection,
  16.             selection,
  17.             null,
  18.             null
  19.         ).use { cursor ->
  20.             if (cursor != null) {
  21.                 while (cursor.moveToNext()) {
  22.                     mainActivityViewModel.allTracksLiveData.value!!.add(
  23.                         Track(
  24.                             cursor.getLong(0),
  25.                             cursor.getString(1),
  26.                             cursor.getString(2),
  27.                             cursor.getString(3),
  28.                             cursor.getString(4),
  29.                             cursor.getLong(5)
  30.                         )
  31.                     )
  32.                 }
  33.             }
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement