我尝试用光标和内容解析器列出所有音频文件,我得到歌曲标题,歌曲和Id的艺术家,但问题是当我尝试在Toast中显示它时,我无法获得它没有返回的路径
感谢您的帮助。
以下是代码以及我如何获取歌曲:
ContentResolver musicResolver = this.getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri,
null,
null,
null,
MediaStore.Audio.Media.TITLE + " ASC");
if(musicCursor!=null && musicCursor.moveToFirst()){
//get columns
int idColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media._ID);
int titleColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.TITLE);
int artistColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int pathColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.DATA);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisPath = musicCursor.getString(pathColumn);
arrayChansons.add(new Chanson(thisId, thisTitle, thisArtist, thisPath));
}
while (musicCursor.moveToNext());
musicCursor.close();