joshriccio
joshriccio

Reputation: 1

Android, Multiple ImageButtons that play an audio clip

I am making an app for a local band. On one screen there are two ImageButtons when clicked they should play different audio clips. The top ImageButton plays the clip great. Although the bottom ImageButton plays the song that the top ImageButton is playing. I'm not getting any errors in the code so i thinkim just not formatting correctly. Thanks

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen2);

   ImageButton btn = (ImageButton)findViewById(R.id.placeyouknow);
   btn.setOnClickListener(this);


   ImageButton btn1 = (ImageButton)findViewById(R.id.fallen);
   btn1.setOnClickListener(this);

}
public void onClick(View v) {
   // TODO Auto-generated method stub

   mp = MediaPlayer.create(this, R.raw.thatplaceyouknow);
   mp.start();


}
public void onClick1(View v) {
    // TODO Auto-generated method stub

    mp = MediaPlayer.create(this, R.raw.fallen);
    mp.start();


 }

Upvotes: 0

Views: 476

Answers (1)

Adam Storm
Adam Storm

Reputation: 724

why would onClick1 ever get called? haha, try something like this:

 public void onClick (View v) {
   switch v.getId() {
   case R.id.placeyouknow:
     mp = MediaPlayer.create(this, R.raw.thatplaceyouknow);
     mp.start();
     break;
   case R.id.fallen:
     mp = MediaPlayer.create(this, R.raw.fallen);
     mp.start();
     break;
   }
 }

cheers

Upvotes: 1

Related Questions