gpt4 book ai didi

android-mediaplayer - 在android中列出专辑

转载 作者:行者123 更新时间:2023-12-04 05:33:21 25 4
gpt4 key购买 nike

我正在 android 中开发一个简单的音频播放器。我想列出设备中的专辑。

我试过这个代码

String where = new String();
where = MediaStore.Audio.Media.IS_MUSIC + "=1";
private Cursor managedCursor;
managedCursor = managedQuery(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] {
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ARTIST_ID
},
where,
null,
MediaStore.Audio.Media.DEFAULT_SORT_ORDER
);

ListAdapter adapter = new AlbumListAdapter(
this,
R.layout.albumlist_item,
managedCursor,
new String[] {
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ARTIST
},
new int[] {
R.id.text_album,
R.id.text_artist
}
);
setListAdapter(adapter);

但是此代码列出了设备中的所有歌曲。

Android Media store DB 的结构是什么。

任何人请帮忙。

最佳答案

你应该像这样查询专辑

String[] projection = new String[] { Albums._ID, Albums.ALBUM, Albums.ARTIST, Albums.ALBUM_ART, Albums.NUMBER_OF_SONGS };
String selection = null;
String[] selectionArgs = null;
String sortOrder = Media.ALBUM + " ASC";
Cursor cursor = contentResolver.query(Albums.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, sortOrder);

http://developer.android.com/reference/android/provider/MediaStore.Audio.Albums.html

艺术家、播放列表和流派都可以使用正确的 EXTERNAL_CONTENT_URI 和相应的投影以类似的方式进行查询。

希望有帮助...

关于android-mediaplayer - 在android中列出专辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9123700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com