变量img的空点异常(在获取艺术家的专辑时)

时间:2013-12-12 06:51:31

标签: android

我正在尝试获取艺术家的所有专辑,我尝试了以下代码但没有帮助..

Uri uri = MediaStore.Audio.Artists.Albums.getContentUri("external", click_no);  
final String artist_name = MediaStore.Audio.Artists.Albums.ALBUM;
final String artist_image_path=MediaStore.Audio.Artists.Albums.ALBUM_ART;
final String[]columns={artist_name,artist_image_path};
//String  String_id = //MediaStore.Audio.Artists._ID
//+ "=?";
int ii=0;
String orderBy = MediaStore.Audio.Artists.Albums.ALBUM;
Cursor  cursor = managedQuery(uri, columns,null,null,null);
//String_id, whereVal, orderBy);
if(cursor != null){
    while(cursor.moveToNext()) {
        img[ii]= cursor.getString(1);
        ii=ii+1;    
    }
}

1 个答案:

答案 0 :(得分:0)

试试我的代码。只需将filePath传递给它。

private void showMetaData(String filePath){
        MediaMetadataRetriever metaDataRetriver= new MediaMetadataRetriever();
        metaDataRetriver.setDataSource(filePath);

        try {
            byte[] art= metaDataRetriver.getEmbeddedPicture();
            Bitmap songImage= BitmapFactory.decodeByteArray(art, 0,               art.length);
            yourImageView.setImageBitmap(songImage);
        } catch (Exception e) {
            Log.v("TAG", e.toString());
        }

        try {
            yourSongTitleTextView.setText(metaDataRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE));

        } catch (Exception e) {
            Log.v("TAG", e.toString());
        }

        try {
            yourAlbumNameTextView.setText(metaDataRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));

        } catch (Exception e) {
            Log.v("TAG", e.toString());
        }

        try {
            yourArtistNameTextView.setText(metaDataRetriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST));

        } catch (Exception e) {
            Log.v("TAG", e.toString());
        }
    }