package com.apofa.demolab1; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class demolab1 extends Activity { /** Called when the activity is first created. */ MediaPlayer mp1, mp2; boolean switchit=false; Button b1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mp1 = new MediaPlayer(); mp1 = MediaPlayer.create(this, R.raw.nextstage); mp2 = new MediaPlayer(); mp2 = MediaPlayer.create(this, R.raw.schoolbell); b1 = (Button)this.findViewById(R.id.play); b1.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(switchit){ mp1.start(); }else{ mp2.start(); } switchit =!switchit; } }); } }