Android 设置相册缩略图
我已经检索了专辑的一些封面艺术(我有 id 和位图),现在我想将其设置到 MediaStore 中。
我尝试了很多东西:
private static final Uri ARTWORK_URI = Uri.parse("content://media/external/audio/albumart");
public static void writeArtwork(Context context, Bitmap bmp, int albumId) {
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(ARTWORK_URI, albumId);
LogUtil.i(TAG, "uri= " + uri);
if (uri != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] bytes = baos.toByteArray();
LogUtil.i(TAG, "Bytes: " + bytes.length);
ContentValues values = new ContentValues();
values.put("album_id", albumId);
values.put("_data", bytes);
res.insert(uri, values);
}
}
这给出了 java.lang.UnsupportedOperationException: Invalid URI content://media/external/audio/albumart/5
我也尝试过:
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(artworkUri, album.getId());
OutputStream outStream = getContentResolver().openOutputStream(uri);
bmp.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
但这给出了 FileNotFoundException。
I have retrieved some cover art for an album (I have the id and a Bitmap) and now I want to set it into the MediaStore.
I tried a bunch of stuff:
private static final Uri ARTWORK_URI = Uri.parse("content://media/external/audio/albumart");
public static void writeArtwork(Context context, Bitmap bmp, int albumId) {
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(ARTWORK_URI, albumId);
LogUtil.i(TAG, "uri= " + uri);
if (uri != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] bytes = baos.toByteArray();
LogUtil.i(TAG, "Bytes: " + bytes.length);
ContentValues values = new ContentValues();
values.put("album_id", albumId);
values.put("_data", bytes);
res.insert(uri, values);
}
}
This gives java.lang.UnsupportedOperationException: Invalid URI content://media/external/audio/albumart/5
Also I tried:
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(artworkUri, album.getId());
OutputStream outStream = getContentResolver().openOutputStream(uri);
bmp.compress(Bitmap.CompressFormat.JPEG, 50, outStream);
But this gives FileNotFoundException.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论