Android 安卓上的封面艺术
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1954434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cover art on android
提问by Mojo Risin
I am developing a sort of media player for android. The question is how can i get the cover art of audio file on android. For example the default android media player shows album covers when listing albums, how can i get this artworks.
我正在为 android 开发一种媒体播放器。问题是我怎样才能在 android 上获得音频文件的封面艺术。例如,默认的 android 媒体播放器在列出专辑时会显示专辑封面,我如何才能获得此艺术品。
回答by Fedor
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ContentResolver res = context.getContentResolver();
InputStream in = res.openInputStream(uri);
Bitmap artwork = BitmapFactory.decodeStream(in);
More complete sample code can be found in Android Music player source here https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/MusicUtils.javamethod getArtworkQuick.
更完整的示例代码可以在此处的 Android 音乐播放器源中找到https://github.com/android/platform_packages_apps_music/blob/master/src/com/android/music/MusicUtils.java方法 getArtworkQuick。
回答by Hitesh Sahu
I don't know why everybody is making it so complicated you can use Glideto achieve this in simplest and efficient way with just 1 line of code
我不知道为什么每个人都把它弄得这么复杂,你可以使用Glide以最简单有效的方式实现这一目标,只需 1 行代码
Declare this path in App Constants -
在 App Constants 中声明此路径 -
final public static Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Get Image Uri using Album ID
使用相册 ID 获取图像 Uri
Uri uri = ContentUris.withAppendedId(PlayerConstants.sArtworkUri,
listOfAlbums.get(position).getAlbumID());
Now simply display album art using uri :-
现在只需使用 uri 显示专辑封面:-
Glide.with(context).load(uri).placeholder(R.drawable.art_default).error(R.drawable.art_default)
.crossFade().centerCrop().into(holder.albumImage);
Glide will handle caching, scaling and lazy loading of images for you.
Glide 将为您处理图像的缓存、缩放和延迟加载。
Hope it help somebody.
希望它可以帮助某人。
回答by Altaf Shaikh
You can use
您可以使用
MediaMetadataRetriever
媒体元数据检索器
class and get track info i.e. Title,Artist,Album,Image
课程并获取曲目信息,即标题、艺术家、专辑、图像
Bitmap GetImage(String filepath) //filepath is path of music file
{
Bitmap image;
MediaMetadataRetriever mData=new MediaMetadataRetriever();
mData.setDataSource(filePath);
try{
byte art[]=mData.getEmbeddedPicture();
image=BitmapFactory.decodeByteArray(art, 0, art.length);
}
catch(Exception e)
{
image=null;
}
return image;
}
回答by Jawad Zeb
Here i can attach one function that is return album art from media store .
在这里,我可以附加一个功能,即从媒体商店返回专辑封面。
Here in function we just have to pass the album_id which we get from Media store .
在函数中,我们只需要传递我们从 Media store 获得的 album_id 。
public Bitmap getAlbumart(Long album_id)
{
Bitmap bm = null;
try
{
final Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
ParcelFileDescriptor pfd = context.getContentResolver()
.openFileDescriptor(uri, "r");
if (pfd != null)
{
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
} catch (Exception e) {
}
return bm;
}
回答by Tim Kryger
Based on your comments to others, it seems like your question is less about Android and more about how to get album art in general. Perhaps this articleon retrieving album art from Amazon will be helpful. Once you have a local copy and store it as Nick has suggested, I believe you should be able to retrieve it the way Fudgey suggested.
根据您对其他人的评论,您的问题似乎不是关于 Android,而是关于如何获取专辑封面。也许这篇关于从亚马逊检索专辑封面的文章会有所帮助。一旦您拥有本地副本并按照 Nick 的建议进行存储,我相信您应该能够按照 Fudgey 建议的方式检索它。
回答by NiklasMM
Android only recognizes files named "AlbumArt.jpg" as Album Covers. Just put the pictures with that name in the album folder and you'll be fine..
Android 仅将名为“AlbumArt.jpg”的文件识别为专辑封面。只需将具有该名称的图片放入相册文件夹中就可以了。
回答by Mottie
I don't know if you read that google is making Stackoverflow the official Android app development Q&A mediumbut for beginner questions... Now, I know nothing about developing in andriod, but a quick search of the Android Developers site, I found this:
我不知道你是否读过谷歌正在让 Stackoverflow 成为官方的 Android 应用程序开发问答媒介,但对于初学者的问题......现在,我对在 Android 中开发一无所知,但是快速搜索 Android 开发者网站,我发现了这个:
Hopefully it'll help.
希望它会有所帮助。