public void accessMetaData(int songIndex)
{
MediaMetadataRetriever retriver = new MediaMetadataRetriever ();
retriver.setDataSource(songsList.get(songIndex).get("songPath"));
showMetaData(retriver);
}
public void showMetaData(MediaMetadataRetriever retriver)
{
// Log.i("Script", "METADATA_KEY_ALBUM: " +retriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
// Log.i("Script", "METADATA_KEY_ALBUMARTIST: " +retriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST));
byte [] imgBytes = retriver.getEmbeddedPicture();
Bitmap bitmap ;
if(imgBytes != null) {
bitmap = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
ImageView ivImage = (ImageView)findViewById(R.id.ivImage);
ivImage.setImageBitmap(bitmap);
/* PlayListActivity.ay7aga = (ImageView)findViewById(R.id.widget_album_art);
ivImage.setImageBitmap(bitmap); */
}
我有这个代码来获取活动A中的专辑封面,我想将相同的专辑封面传递给活动B,这个代码获取当前播放歌曲的专辑封面
如果我遵循您的问题,那么您可以将图像从一个活动传递到另一个活动。转换您的专辑封面ImageView位图。设置你的ImageView的DrawingCache为true,然后将背景保存为位图,并通过putExtra传递。
image.setDrawingCacheEnabled(true);
Bitmap b=image.getDrawingCache();
Intent i = new Intent(this, nextActivity.class);
i.putExtra("Bitmap", b);
startActivity(i);
在你的下一个活动中
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Bitmap");
imageView.setImageBitmap(bitmap);
btnPlaylist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
/* Intent i = new Intent(getApplicationContext(), PlayListActivity.class);
Bitmap bmOriginal = BitmapFactory.decodeResource(getResources(), R.id.ivImage);
i.putExtra("ha",bmOriginal);
startActivityForResult(i, 100); */
Intent i = new Intent(getApplicationContext(), PlayListActivity.class);
ivImage.buildDrawingCache();
Bitmap bitmap = ivImage.getDrawingCache();
i.putExtra("BitmapImage", bitmap);
}
});
}
/**
* Receiving song index from playlist view
* and play the song
* */
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100){
currentSongIndex = data.getExtras().getInt("songIndex");
// play selected song
playSong(currentSongIndex);
}
}
/**
* Function to play a song
* @param songIndex - index of song
* */
public void playSong(int songIndex){
// Play song
try {
mp.reset();
accessMetaData(songIndex); // here i can show albumart in Activity A
mp.setDataSource(songsList.get(songIndex).get("songPath"));
mp.prepare();
mp.start();
// Displaying Song title
String songTitle = songsList.get(songIndex).get("songTitle");
songTitleLabel.setText(songTitle);
// Changing Button Image to pause image
btnPlay.setImageResource(R.drawable.btn_pause);
// set Progress bar values
songProgressBar.setProgress(0);
songProgressBar.setMax(100);
// Updating progress bar
updateProgressBar();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Activity B
// public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);
getActionBar().hide();
ay7aga = (ImageView)findViewById(R.id.widget_album_art);
Bundle bundle = this.getIntent().getExtras();
Bitmap bmA = bundle.getParcelable("ha");
ay7aga.setImageBitmap(bmA);
public void accessMetaData(int songIndex)
{
MediaMetadataRetriever retriver = new MediaMetadataRetriever ();
retriver.setDataSource(songsList.get(songIndex).get("songPath"));
showMetaData(retriver);
}
public void showMetaData(MediaMetadataRetriever retriver)
{
// Log.i("Script", "METADATA_KEY_ALBUM: " +retriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM));
// Log.i("Script", "METADATA_KEY_ALBUMARTIST: " +retriver.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST));
byte [] imgBytes = retriver.getEmbeddedPicture();
Bitmap bitmap ;
if(imgBytes != null) {
bitmap = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
ImageView ay7aga = (ImageView)findViewById(R.id.widget_album_art);
ay7aga.setImageBitmap(bitmap);
}