0
我使用此代碼獲取MediaStore中的所有音樂,但不僅僅是音樂,我的列表中包含我設備中的所有音樂以及「facebook」或「skype」等應用程序的聲音。如何避免這種情況?如何在沒有應用程序歌曲的情況下列出MediaStore中的所有音樂
public void getSongList(){
//query external audio
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Toast.makeText(PlayListActivity.this, musicUri.getPath(), Toast.LENGTH_LONG).show();
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 albumColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ALBUM_ID);
//add songs to list
Bitmap bmThumbnail;
do {
String path = musicCursor.getString(musicCursor.getColumnIndex(MediaStore.Audio.Media.DATA));
long thisId = musicCursor.getLong(idColumn);
long thisAlbumId = musicCursor.getLong(albumColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
songList.add(new Song(thisId, thisAlbumId, thisTitle, thisArtist, path));
}
while (musicCursor.moveToNext());
}
}
我會試試,非常感謝 –