Created
September 4, 2021 13:25
-
-
Save MohitSharma0101/d69243ab9b6de6173b672c83d9d0215a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MainActivity.kt: (66, 13): Unresolved reference: MediaStore