建議
嗨!用簡單的音樂播放器查看my repository。歌曲從外部存儲裝載。 Pre-Lollipop支持。
SOLUTION
至於你的問題,用歌聲負載的解決方案:你可以加載從外部存儲的歌曲是這樣的:
私人ArrayList的歌曲=新的ArrayList <>(); //宋是一些數據模型
public void getSongList() {
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
// song title
int titleColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.TITLE);
// song unique id
int idColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media._ID);
// song's artist
int artistColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.ARTIST);
// path to album art
int albumIdColumn = musicCursor.getColumnIndex
(MediaStore.Audio.Media.ALBUM_ID);
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
long albumId = musicCursor.getLong(albumIdColumn);
String albumArt = "";
try {
albumArt = (ContentUris.withAppendedId(artworkUri, albumId)).toString();
Log.d(TAG, "TEST Album art: " + albumArt);
} catch (Exception ex) {
ex.printStackTrace();
}
// Adding new song to ArrayList
songs.add(new Song(thisId, thisTitle, thisArtist, albumArt));
}
while (musicCursor.moveToNext());
}
if (musicCursor != null)
musicCursor.close();
}
看看如何使用內部存儲:http://developer.android.com/guide/topics/data/data-storage.html#filesInternal – reinder