Skip to content

Instantly share code, notes, and snippets.

@MohitSharma0101
Created September 4, 2021 13:25
Show Gist options
  • Save MohitSharma0101/d69243ab9b6de6173b672c83d9d0215a to your computer and use it in GitHub Desktop.
Save MohitSharma0101/d69243ab9b6de6173b672c83d9d0215a to your computer and use it in GitHub Desktop.
fun getAllAudioFiles(): MutableList<String> {
val songs: MutableList<String> = ArrayList()
val selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"
val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION
)
applicationContext.contentResolver.query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
null,
null
)?.use{ cursor ->
while (cursor.moveToNext()) {
songs.add(
cursor.getString(0)
.toString() + "||" + cursor.getString(1) + "||" + cursor.getString(2) + "||" + cursor.getString(
3
) + "||" + cursor.getString(4) + "||" + cursor.getString(5)
)
}
}
return songs
}
@devfemibadmus
Copy link

MainActivity.kt: (66, 13): Unresolved reference: MediaStore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment