如题,
求教各位大神:
在做一个基于android平台的音乐播放器  
想问下使用Cursor getContentResolver().query如何获得专辑图片?因为项目日期快到了,比较着急先行拜谢~~~

解决方案 »

  1.   

    查询后先获得歌曲ID
    int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); 然后根据歌曲ID读取专辑图片路径,但不是每个歌曲文件都自带专辑图片
    String musicPic = getAlbumArt(id);
        private String getAlbumArt(int trackId) {//trackId是音乐的id
            String mUriTrack = "content://media/external/audio/media/#";
            String[] projection = new String[] {"album_id"};
            String selection = "_id = ?";
            String[] selectionArgs = new String[] {Integer.toString(trackId)};        
            Cursor cur = this.getContentResolver().query(Uri.parse(mUriTrack), projection, selection, selectionArgs, null);
            int album_id = 0;
            if (cur.getCount() > 0 && cur.getColumnCount() > 0) {
                cur.moveToNext();
                album_id = cur.getInt(0);
            }
            cur.close();
            cur = null;        if (album_id < 0) {
                return null;
            }
            String mUriAlbums = "content://media/external/audio/albums";
            projection = new String[] {"album_art"};
            cur = this.getContentResolver().query(Uri.parse(mUriAlbums + "/" + Integer.toString(album_id)), projection, null, null, null);        String album_art = null;
            if (cur.getCount() > 0 && cur.getColumnCount() > 0) {
                cur.moveToNext();
                album_art = cur.getString(0);
            }
            cur.close();
            cur = null;
                
            return album_art;
        }