Example #1
0
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case EVENT_DOWNLOADCOVER:
       Bitmap cover = null;
       for (ICoverRetriever coverRetriever : coverRetrievers) {
         cover = getBitmapForRetriever((CoverInfo) msg.obj, coverRetriever);
         if (cover != null) {
           Log.i("Found cover art using retriever : " + coverRetriever.getName());
           // if cover is not read from cache and saving is enabled
           if (cacheWritable && !(coverRetriever instanceof CachedCover)) {
             // Save this cover into cache, if it is enabled.
             for (ICoverRetriever coverRetriever1 : coverRetrievers) {
               if (coverRetriever1 instanceof CachedCover) {
                 Log.i("Saving cover art to cache");
                 ((CachedCover) coverRetriever1)
                     .save(((CoverInfo) msg.obj).sArtist, ((CoverInfo) msg.obj).sAlbum, cover);
               }
             }
           }
           CoverAsyncHelper.this.obtainMessage(EVENT_COVERDOWNLOADED, cover).sendToTarget();
           break;
         }
       }
       if (cover == null) {
         Log.i("No cover art found");
         CoverAsyncHelper.this.obtainMessage(EVENT_COVERNOTFOUND).sendToTarget();
       }
       break;
     default:
   }
 }
Example #2
0
    public Bitmap getBitmapForRetriever(CoverInfo info, ICoverRetriever retriever) {
      String[] urls = null;
      try {
        // Get URL to the Cover...
        urls = retriever.getCoverUrl(info.sArtist, info.sAlbum, info.sPath, info.sFilename);
      } catch (Exception e) {
        Log.w(e);
        return null;
      }

      if (urls == null || urls.length == 0) {
        return null;
      }

      Bitmap downloadedCover = null;
      for (String url : urls) {
        if (url == null) continue;
        Log.i("Downloading cover art at url : " + url);
        if (retriever.isCoverLocal()) {
          int maxSize = coverMaxSize;
          if (cachedCoverMaxSize != MAX_SIZE) {
            maxSize = cachedCoverMaxSize;
          }

          if (maxSize == MAX_SIZE) {
            downloadedCover = BitmapFactory.decodeFile(url);
          } else {
            downloadedCover = Tools.decodeSampledBitmapFromPath(url, maxSize, maxSize, false);
          }
        } else {
          downloadedCover = download(url);
        }

        if (downloadedCover != null) {
          break;
        }
      }
      return downloadedCover;
    }