コード例 #1
0
  public static void setAlbumArt(ImageView imageview, String file, boolean compress) {

    String albumArtpath = allSongsList.getAlbumArt(file);

    if (albumArtpath != null) {
      File albumArtFile = new File(albumArtpath);
      Bitmap bm = null;
      InputStream iStream1 = null;
      InputStream iStream2 = null;

      try {

        iStream1 = new BufferedInputStream(new FileInputStream(albumArtFile));
        if (!compress) {
          bm = BitmapFactory.decodeStream(iStream1);
        } else {
          iStream2 = new BufferedInputStream(new FileInputStream(albumArtFile));
          bm = decodeFile2(iStream1, iStream2, 100, 100);
        }
        imageview.setImageBitmap(bm);

      } catch (FileNotFoundException e) {

        MediaMetadataRetriever md = new MediaMetadataRetriever();
        md.setDataSource(file);
        byte[] art = md.getEmbeddedPicture();
        if (art != null) {

          iStream1 = new ByteArrayInputStream(md.getEmbeddedPicture());

          if (!compress) {

            bm = BitmapFactory.decodeStream(iStream1);
          } else {
            iStream2 = new ByteArrayInputStream(md.getEmbeddedPicture());
            bm = decodeFile2(iStream1, iStream2, 100, 100);
          }
          imageview.setImageBitmap(bm);
        } else {
          imageview.setImageDrawable(
              imageview
                  .getContext()
                  .getResources()
                  .getDrawable(R.drawable.ic_expandplayer_placeholder));
        }
      }
    } else {
      imageview.setImageDrawable(
          imageview
              .getContext()
              .getResources()
              .getDrawable(R.drawable.ic_expandplayer_placeholder));
    }
  }
コード例 #2
0
  // two extra methods for async-loading of images
  public static Bitmap decodeAlbumArt(String file, boolean compress) {

    Bitmap toReturn = null;

    String albumArtpath = allSongsList.getAlbumArt(file);

    if (albumArtpath != null) {
      File albumArtFile = new File(albumArtpath);
      Bitmap bm = null;
      InputStream iStream1 = null;
      InputStream iStream2 = null;

      try {

        iStream1 = new BufferedInputStream(new FileInputStream(albumArtFile));
        if (!compress) {
          bm = BitmapFactory.decodeStream(iStream1);
        } else {
          iStream2 = new BufferedInputStream(new FileInputStream(albumArtFile));
          bm = decodeFile2(iStream1, iStream2, 100, 100);
        }

      } catch (FileNotFoundException e) {

        MediaMetadataRetriever md = new MediaMetadataRetriever();
        md.setDataSource(file);
        byte[] art = md.getEmbeddedPicture();
        if (art != null) {

          iStream1 = new ByteArrayInputStream(md.getEmbeddedPicture());

          if (!compress) {

            bm = BitmapFactory.decodeStream(iStream1);
          } else {
            iStream2 = new ByteArrayInputStream(md.getEmbeddedPicture());
            bm = decodeFile2(iStream1, iStream2, 100, 100);
          }
        }
      }
      toReturn = bm;
    }
    return toReturn;
  }