80,471
社区成员




private Bitmap getArtworkFromFile(Context context2, long songID, long albumID) {
Bitmap bitmap = null;
if (songID < 0 && albumID < 0) {
throw new IllegalArgumentException("Must specify an album or a song id");
}
BitmapFactory.Options options = new BitmapFactory.Options();
FileDescriptor fd = null;
if (albumID < 0) {
Uri uri = Uri.parse("content://media/external/audio/media/" + songID + "/albumart");
try {
ParcelFileDescriptor dfd = context2.getContentResolver().openFileDescriptor(uri, "r");
if (dfd != null) {
fd = dfd.getFileDescriptor();
}
} catch (FileNotFoundException e) {
// e.printStackTrace();
}
} else {
Uri uri = ContentUris.withAppendedId(artworkUri, albumID);
try {
ParcelFileDescriptor dfd = context2.getContentResolver().openFileDescriptor(uri, "r");
if (dfd != null) {
fd = dfd.getFileDescriptor();
}
} catch (FileNotFoundException e) {
// e.printStackTrace();
}
}
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
options.inSampleSize = 500;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFileDescriptor(fd, null, options);
return bitmap;
}
private Bitmap getArtworkFromFile(Context context2, long songID, long albumID) {
Bitmap bitmap = null;
if (songID < 0 && albumID < 0) {
throw new IllegalArgumentException(
"Must specify an album or a song id");
}
try {
BitmapFactory.Options options = new BitmapFactory.Options();
FileDescriptor fd = null;
if (albumID < 0) {
Uri uri = Uri.parse("content://media/external/audio/media/" + songID + "/albumart");
ParcelFileDescriptor dfd = context2.getContentResolver().openFileDescriptor(uri, "r");
if (dfd != null) {
fd = dfd.getFileDescriptor();
}
} else {
Uri uri = ContentUris.withAppendedId(artworkUri, albumID);
ParcelFileDescriptor dfd = context2.getContentResolver().openFileDescriptor(uri, "r");
if (dfd != null) {
fd = dfd.getFileDescriptor();
}
}
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
options.inSampleSize = 500;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFileDescriptor(fd, null, options);
} catch (Exception e) {
e.printStackTrace() ;
}
return bitmap;
}