如何设置我们作为图形图像在Android上的MP3专辑 [英] how to set our image as artwork in a mp3 album in android
本文介绍了如何设置我们作为图形图像在Android上的MP3专辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了我们想要插入为其.MP3文件,没有任何艺术品艺术品的应用程序。还有我也想取代旧的作品与SD卡拍摄的新形象,每当我要恢复老的作品,能够检索。请帮助别人。
I am creating an application in which we want to insert an artwork for which .mp3 file which have no any artwork. as well as i also want to replace old artwork with new image taken from sdcard, and whenever i want to restore old artwork, able to retrieve it. please help someone.
推荐答案
希望这有助于你 -
Hope this help you-
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.
Bitmap bm = getArtworkFromFile(context, null, album_id);
if (bm != null) {
// Put the newly found artwork in the database.
// Note that this shouldn't be done for the "unknown" album,
// but if this method is called correctly, that won't happen.
// first write it somewhere
String file = Environment.getExternalStorageDirectory()
+ "/albumthumbs/" + String.valueOf(System.currentTimeMillis());
if (ensureFileExists(file)) {
try {
OutputStream outstream = new FileOutputStream(file);
if (bm.getConfig() == null) {
bm = bm.copy(Bitmap.Config.RGB_565, false);
if (bm == null) {
return getDefaultArtwork(context);
}
}
boolean success = bm.compress(Bitmap.CompressFormat.JPEG, 75, outstream);
outstream.close();
if (success) {
ContentValues values = new ContentValues();
values.put("album_id", album_id);
values.put("_data", file);
Uri newuri = res.insert(sArtworkUri, values);
if (newuri == null) {
// Failed to insert in to the database. The most likely
// cause of this is that the item already existed in the
// database, and the most likely cause of that is that
// the album was scanned before, but the user deleted the
// album art from the sd card.
// We can ignore that case here, since the media provider
// will regenerate the album art for those entries when
// it detects this.
success = false;
}
}
if (!success) {
File f = new File(file);
f.delete();
}
} catch (FileNotFoundException e) {
Log.e(TAG, "error creating file", e);
} catch (IOException e) {
Log.e(TAG, "error creating file", e);
}
}
} else {
bm = getDefaultArtwork(context);
}
return bm;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
}
}
}
来自答案 - <一个href=\"http://stackoverflow.com/questions/2504726/how-can-i-update-the-album-art-path-using-contentresolver\">How使用ContentResolver的我可以更新专辑封面路径?
这篇关于如何设置我们作为图形图像在Android上的MP3专辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文