我正在制作音乐应用 . 到目前为止,一切都很顺利 . 我想要播放专辑封面以及播放的歌曲 . 但我无法弄清楚这样做的方法 .
您可以使用 MediaMetaDataRetriever class从媒体文件中获取所有元数据 .
MediaMetaDataRetriever
代码如下:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); getInit(); // Ablum_art retrieval code // metaRetriver = new MediaMetadataRetriever(); metaRetriver.setDataSource("/sdcard/audio.mp3"); try { art = metaRetriver.getEmbeddedPicture(); Bitmap songImage = BitmapFactory .decodeByteArray(art, 0, art.length); album_art.setImageBitmap(songImage); album.setText(metaRetriver .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)); artist.setText(metaRetriver .extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)); genre.setText(metaRetriver .extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE)); } catch (Exception e) { album_art.setBackgroundColor(Color.GRAY); album.setText("Unknown Album"); artist.setText("Unknown Artist"); genre.setText("Unknown Genre"); } } // Fetch Id's form xml public void getInit() { album_art = (ImageView) findViewById(R.id.album_art); album = (TextView) findViewById(R.id.Album); artist = (TextView) findViewById(R.id.artist_name); genre = (TextView) findViewById(R.id.genre); } }
你可以使用以下功能(api> 10)
Bitmap getEmbeddedPicture(String songPath){ android.media.MediaMetadataRetriever mmr = new MediaMetadataRetriever(); mmr.setDataSource(songsList.get(songIndex).get("songPath")); byte [] data = mmr.getEmbeddedPicture(); //coverart is an Imageview object // convert the byte array to a bitmap if(data != null) { return BitmapFactory.decodeByteArray(data, 0, data.length); } else return null; }
你可以使用Picasso,它使加载图像变得非常容易,并有一些不错的选择 .
基本上,您只需要您的imageView(或所有这些并循环并加载每个图像)和图像的URI .
Picasso.with(context) .load(uri) .into(imageView);
链接到毕加索有趣而简单的教程:
http://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149
3 回答
您可以使用
MediaMetaDataRetriever
class从媒体文件中获取所有元数据 .代码如下:
你可以使用以下功能(api> 10)
你可以使用Picasso,它使加载图像变得非常容易,并有一些不错的选择 .
基本上,您只需要您的imageView(或所有这些并循环并加载每个图像)和图像的URI .
链接到毕加索有趣而简单的教程:
http://code.tutsplus.com/tutorials/android-sdk-working-with-picasso--cms-22149