这是我的代码:
//query external audio
ContentResolver musicResolver = getContentResolver();
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
//iterate over results if valid
if (musicCursor != null && musicCursor.moveToFirst()) {
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int file = musicCursor.getColumnIndex(MediaStore.Audio.Media.DATA);
int durationTime = musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisPath = musicCursor.getString(file);
String thisDuration = musicCursor.getString(durationTime);
thisDuration = getTime(Long.valueOf(thisDuration));
if (thisPath != null) {
mmr.setDataSource(thisPath);
}
if (mmr.getEmbeddedPicture() != null) {
byte[] art = mmr.getEmbeddedPicture();
bitmap = null;
if (art != null) {
bitmap = BitmapFactory.decodeByteArray(art, 0, art.length);
} else {
bitmap = BitmapFactory.decodeFile(thisPath);
}
}
songList.add(new Song(thisId, thisTitle, thisArtist, thisPath, thisDuration, bitmap));
}
while (musicCursor.moveToNext());
}
引起:java.lang.RuntimeException:setDataSource failed:status = 0xFFFFFFEA 在android.media.MediaMetadataRetriever.setDataSource(本机方法) 在android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:66)
和Uri musicUri = EXTERNAL_CONTENT_URI
;