0
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); */

    }

i have this code to get album art in Activity A ,, i want to pass same album art to Activity B and this code get album art for the current play song

  • You can pass the bitmap through Intent extra, so once you get the bitmap pass the bitmap through extra to other activity, else create some object set the value and pass it through the intent – Shambhavi Oct 10 '15 at 11:26
  • @Shambhavi i'm new in android can you help me and show how can i do this according to my code – Seif Al Ashmawe Oct 10 '15 at 11:33
  • Sure, Intent intentNotif= new Intent(getApplicationContext(), YourSecondActivity.class); intentNotif.putExtra("ImageBitmap", YourBitmapValue); startActivity(intentNotif); – Shambhavi Oct 10 '15 at 11:35
  • @Shambhavi i make it like this Intent i = new Intent(getApplicationContext(), PlayListActivity.class); Bitmap bmOriginal = BitmapFactory.decodeResource(getResources(), R.id.ivImage); i.putExtra("ha",bmOriginal); startActivityForResult(i, 100); but not working when i recode R.id.ivImage to R.drawable.anyPic working fine are this way to pass for only drawable ?! – Seif Al Ashmawe Oct 10 '15 at 12:00
  • is there a value in bmOriginal? when you debug it? I mean is the value being passed for sure? – Shambhavi Oct 10 '15 at 12:03
  • @Shambhavi when i make it like R.drawable.anyPic it pass this pic to Activity B but i don't want the pic from drawable i need that album art i get from that above code i think when i pass R.id.ivImage it will pass the album art sorry about my english and my code :D – Seif Al Ashmawe Oct 10 '15 at 12:13
  • Oh! okay so you need to get the bitmap in the first Activity itself and then pass that bitmap and not the image! Correct me if this not the doubt – Shambhavi Oct 10 '15 at 12:15
  • @Shambhavi yes ,, i'm realy confused – Seif Al Ashmawe Oct 10 '15 at 12:25
  • Tell me the exact steps that you have followed – Shambhavi Oct 10 '15 at 12:26
  • @Shambhavi if you look in showMetaData(); you will find R.id.IvImage i take this refe and but it in Intent i = new Intent(getApplicationContext(), PlayListActivity.class); Bitmap bmOriginal = BitmapFactory.decodeResource(getResources(), R.id.ivImage); i.putExtra("ha",bmOriginal); startActivityForResult(i, 100); here and i think it will pass the image in Activity B when i change to R.drawable.anyPic this pic in drawable pass in Activity B it just for try – Seif Al Ashmawe Oct 10 '15 at 12:41
  • @Seif Al Ashmawe ....did you try my answer? – SRB Bans Oct 10 '15 at 12:43
  • @sourabhbans i try it but it's give emptyimage – Seif Al Ashmawe Oct 10 '15 at 12:45
  • are you able to show the image in first activity's imageview? – SRB Bans Oct 10 '15 at 12:48
  • @sourabhbans yes ,,, accessMetaData(int songIndex); i call this method in playSong(int songIndex); and when the song start the image appear – Seif Al Ashmawe Oct 10 '15 at 12:53
  • can you put the whole code... where you are sending image and receiving it. cuz it is a tested code. – SRB Bans Oct 10 '15 at 12:55
  • @sourabhbans ay7aga = (ImageView)findViewById(R.id.widget_album_art); Bundle bundle = this.getIntent().getExtras(); Bitmap bmA = bundle.getParcelable("ha"); ay7aga.setImageBitmap(bmA); i receive it in Activity B in this way – Seif Al Ashmawe Oct 10 '15 at 12:56
  • and how are you sending it(sending code)... and from where? and make sure image view is not blank when you sending it from first activity. – SRB Bans Oct 10 '15 at 13:02
  • @sourabhbans i put the whole code in answer – Seif Al Ashmawe Oct 10 '15 at 13:10
  • see the comment in your answer. match the keys... of receiving and sending. – SRB Bans Oct 10 '15 at 13:11

2 Answers2

0

if i follow your question than you can pass image from one activity to another. Convert your album art ImageView to Bitmap. Set the DrawingCache of your ImageView to be true and then save the background as a Bitmap and pass it via putExtra.

 image.setDrawingCacheEnabled(true);
  Bitmap b=image.getDrawingCache();
  Intent i = new Intent(this, nextActivity.class);

  i.putExtra("Bitmap", b);
  startActivity(i);

And in your Next Activity,

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("Bitmap");
imageView.setImageBitmap(bitmap);
SRB Bans
  • 3,096
  • 1
  • 10
  • 21
0
 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);



    }
  • change the receiving key as (BitmapImage) not (ha).. Bitmap bmA = bundle.getParcelable("BitmapImage"); You are using different key for sending and receiving image – SRB Bans Oct 10 '15 at 13:09
  • @sourabhbans i edit it ,, still trying but nothing change – Seif Al Ashmawe Oct 10 '15 at 13:47
  • @ @sourabhbans ""Activity A "" `btnPlaylist.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { ivImage.setDrawingCacheEnabled(true); Bitmap b=ivImage.getDrawingCache(); Intent i = new Intent(getApplicationContext(), PlayListActivity.class); i.putExtra("Bitmap", b); startActivity(i);` ""Activity B"" ` ay7aga = (ImageView)findViewById(R.id.widget_album_art); Intent s = new Intent (); Bitmap bitmap = (Bitmap) s.getParcelableExtra("Bitmap"); ay7aga.setImageBitmap(bitmap); ` – Seif Al Ashmawe Oct 10 '15 at 14:27