我正在开发一款适用于Android的音乐播放器,我希望能够帮助制作背景颜色与播放歌曲的专辑艺术相同,如Sony Walkman。
我尝试了下面的代码,但它不起作用。
有人可以指导或帮助我如何使其发挥作用吗?
public void updatePlayerBar(Bitmap bitmap) {
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (swatch == null) swatch = palette.getMutedSwatch(); // Sometimes vibrant swatch is not available
if (swatch != null) {
album_art.setBackgroundColor(swatch.getRgb());
album.setTextColor(swatch.getTitleTextColor());
artist.setTextColor(swatch.getBodyTextColor());
}
}
});
}
public void acv(String path) { //method for retrieving album art
metaRetriver = new MediaMetadataRetriever();
metaRetriver.setDataSource(path);
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));
updatePlayerBar(songImage); //calling method updatePlayerBar here
} catch (Exception e) {
album.setText("Unknown Album");
artist.setText("Unknown Artist");
}
}