想做一个android播放器,需要在播放的时候显示被播放音乐的专辑的图片,好像专辑图片是集成在音乐文件内部的,我用电脑里的windows media player播放歌曲的时候旁边会显示一个音乐专辑的图片(当然很多是没有的,但是有一个默认的),如果没有windwos media player 会提示粘贴一个上去,我试试,可以粘贴,粘完以后再播放就可以显示专辑图片了,那在android系统中,我在代码里该怎么样获得音乐文件里的专辑图片信息呢?
------解决方案--------------------
这个是 mp3 的id3的信息... 可以去找第三方包 解析 mp3 id信息的.当然也可以自己写...
不是所有的MP3里面都包含有专辑图片信息...
\jid3lib-0.5.4 用过这个包....
图片没试过 取其他的 歌词这些还是很好用的.
自己改过一些编码问题 需要的话 可以发个邮件
------解决方案--------------------
ID3信息在android opencore里是解析出来了的,由MediaScanner写入了Media数据库,可以通过查询Media数据库查询出Album信息
------解决方案--------------------
写成文件了。。。这是Android Music里的代码:
// get album art for specified file
private static final String sExternalMediaUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString();
private static Bitmap getArtworkFromFile(Context context, long songid, long albumid) {
Bitmap bm = null;
byte [] art = null;
String path = null;
if (albumid < 0 && songid < 0) {
throw new IllegalArgumentException("Must specify an album or a song id");
}
try {
if (albumid < 0) {
Uri uri = Uri.parse("content://media/external/audio/media/" + songid + "/albumart");
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
} else {
Uri uri = ContentUris.withAppendedId(sArtworkUri, albumid);
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
}
}
} catch (FileNotFoundException ex) {
//
}
if (bm != null) {
mCachedBit = bm;
}
return bm;
}
------解决方案--------------------
还有就是LZ得注意解析的版本, ID3V1还是ID3V2 , 两种方式解析方法是基本不一样的。
ID3V1歌曲信息是保存在最后128个字节里面的 , ID3V2没具体解析过。
------解决方案--------------------
正解是 我把8楼的复制粘贴了,直接就能用。 谢谢各位。