问题
I'm working on audio and video player. I got all video's folder name using mediastore.video.media.bucket_display_name
, it's working perfectly with video files but when i uses mediastore.audio.media.bucket_display_name
it shows error. Can anybody help me to get name of folders containing audio files. I need to do this using cursor. And i got this error:
"no such column: bucket_display_name (Sqlite code 1): , while compiling: SELECT bucket_display_name FROM audio"
回答1:
Use below code to get folders name:
fun getFolderName() {
val uri: Uri
val cursor: Cursor?
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
val projection = arrayOf(MediaStore.Audio.AudioColumns.DATA)
cursor = requireActivity().contentResolver.query(uri, projection, null, null, null)
if (cursor != null) {
column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.DATA)
}
while (cursor!!.moveToNext()) {
absolutePathOfImage = cursor.getString(column_index_data)
val fileName: String = File(absolutePathOfImage).parentFile.name
}
}
来源:https://stackoverflow.com/questions/59460585/how-to-get-name-of-directory-having-audio-files-using-mediastore-audio-in-androi