From 5a95beb93472dea029944577d4d5c557f1aca55d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 16 Feb 2014 11:32:19 -0800 Subject: Don't create a bitmap unless necessary, recycle after download --- src/github/daneren2005/dsub/service/DownloadFile.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java index 9ecfe0ad..d25d2dc9 100644 --- a/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/src/github/daneren2005/dsub/service/DownloadFile.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.OutputStream; import android.content.Context; +import android.graphics.Bitmap; import android.net.wifi.WifiManager; import android.os.PowerManager; import android.util.DisplayMetrics; @@ -432,9 +433,17 @@ public class DownloadFile { private void downloadAndSaveCoverArt(MusicService musicService) throws Exception { try { if (song.getCoverArt() != null) { - DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - int size = Math.min(metrics.widthPixels, metrics.heightPixels); - musicService.getCoverArt(context, song, size, null); + // Check if album art already exists, don't want to needlessly load into memory + File albumArtFile = FileUtil.getAlbumArtFile(context, song); + if(!albumArtFile.exists()) { + DisplayMetrics metrics = context.getResources().getDisplayMetrics(); + int size = Math.min(metrics.widthPixels, metrics.heightPixels); + Bitmap bitmap = musicService.getCoverArt(context, song, size, null); + // Not being used, get rid of it immediately + if(bitmap != null) { + bitmap.recycle(); + } + } } } catch (Exception x) { Log.e(TAG, "Failed to get cover art.", x); -- cgit v1.2.3