0
여기에 아티스트의 그룹 행이있는 확장 가능한 목록보기가 생성되었으며 하위 앨범 아트가있는 아티스트의 모든 앨범이 표시됩니다. 그러나 메모리 예외가 발생합니다.AlbumArt를 가져 오는 중 메모리 부족 예외가 발생했습니다.
public static Bitmap getArtwork(Context context, int album_id) {
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
if (uri != null)
{
InputStream in = null;
try
{
in = res.openInputStream(uri);
return BitmapFactory.decodeStream(in, null, sBitmapOptions);
} catch (FileNotFoundException ex)
{
// The album art thumbnail does not actually exist. Maybe the user deleted it, or
// maybe it never existed to begin with.
} finally
{
if (in != null)
{
try
{
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
return null;
}
그리고 난이 작업을 수행 한 아이의 앨범 목록을 만드는 : 여기
내 코드는 이미지를 얻는 것입니다private ArrayList<ArrayList<HashMap<String, Object>>> createChildList() {
for (int i = 0; i < songsListData.size(); i++)
{
ArrayList<HashMap<String,Object>> secList = new ArrayList<HashMap<String,Object>>();
String s[] = new String[]{songsListData.get(i).get("artistname")};
String whereClause = MediaStore.Audio.Albums.ARTIST + " = ? ";
Cursor cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,null ,whereClause,s,null);
if (cursor == null)
{
//Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
//No media on the device.
}
else
{
int albumName = cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM);
int id = cursor.getColumnIndex(MediaStore.Audio.Albums._ID);
int songcount = cursor.getColumnIndex(MediaStore.Audio.Albums.NUMBER_OF_SONGS);
for(int j=0;j<cursor.getCount();j++)
{
String Name = cursor.getString(albumName);
Integer albumid = cursor.getInt(id);
Bitmap bitmap = null;
bitmap = getArtwork(context, albumid); //calling function
if(bitmap == null)
{
bitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.wallpaper);
}
HashMap<String, Object> album = new HashMap<String, Object>();
album.put("albumName",Name);
album.put("albumId", albumid);
album.put("image", bitmap); //storing image
album.put("songcount",cursor.getString(songcount) + " song");
secList.add(album);
cursor.moveToNext();
}
}
cursor.close();
albumData.add(secList);
}
return albumData;
}
내가 메모리 예외에서 처리해야한다.? ? 나에게 해결책을 좀주세요. 고맙습니다.
내가해야 해시 맵에 저장하기 전에 비트 맵 이미지의 높이와 너비를 줄입니까 ?? – zanky
예 첫번째로 문서를 읽은 다음 코드를 디버그하고 힙 크기를 확인하십시오. 비트 맵의 크기를 줄이면 위의 코드를 사용할 수 있습니다. –
ohk thanx..i 시도 중입니다. – zanky