0
在Android中如何獲取音頻文件w enter image description here第i個縮略圖進入列表視圖?在Android中如何獲取帶有縮略圖的音頻文件到ListView中?
在Android中如何獲取音頻文件w enter image description here第i個縮略圖進入列表視圖?在Android中如何獲取帶有縮略圖的音頻文件到ListView中?
這裏從存儲 -
public class SongsManager{
// SDCard Path
private ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
Cursor cursor;
String[] projection = { MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION
};
@SuppressWarnings("deprecation")
public void getCursor(Activity context) {
cursor = context.managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
selection, null, null);
}
public ArrayList<HashMap<String, String>> getPlayList() {
while (cursor.moveToNext()) {
HashMap<String, String> song = new HashMap<String, String>();
song.put("ID", cursor.getString(0));
song.put("songTitle", cursor.getString(1));
song.put("songPath", cursor.getString(2));
song.put("Artist", cursor.getString(3));
song.put("Duration", cursor.getString(4));
songsList.add(song);
}
// return songs list array
return songsList;
}
代碼來獲取音頻代碼使用音頻ID在ListAdapter getview方法
Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri,
Long.parseLong(songsList.get(position).get("ID")));
songimage.setImageURI(uri);
感謝您的回覆讓音頻拇指.. – Rakhiii
'managedQuery()'有已被棄用**六年**。請停止使用它。在後臺線程上使用'ContentResolver',或使用'CursorLoader'。 – CommonsWare