android-mediaplayer - 在android中列出专辑

标签 android-mediaplayer mediastore albumart

我正在 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/

相关文章:

android - 重叠的 mp4 文件的无缝播放

java - 错误:调用需要API级别23(当前最小值为15):

android - 为什么我无法从 MediaStore 获取视频时长?

Android:如何从歌曲中排除铃声和通知

android - 在 Media Player Android 上播放来自 MediaStore 的音频

android - 创建按字母顺序排序歌曲的 ListView android

android - 使用服务与 MediaPlayer 和 SoundPool

android - 我可以从 MediaPlayer 或 SoundPool 获取原始 PCM 数据吗?

python - 诱变剂:如何在 mp3、flac 和 mp4 中检测和嵌入专辑封面

android - 如何在锁屏中设置全屏专辑封面?