I have following piece of code to stop media player
While pressing start button it starts playing the mp3 file, but it doesn't
stop while pressing Stop button, I have been through few examples but
couldn't find the exact solution
public Button play;
public Button stop;
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play = (Button)findViewById(R.id.played);
stop = (Button)findViewById(R.id.stopped);
play.setOnClickListener(this);
stop.setOnClickListener(this);
}
public void onClick(View v) {
mp = MediaPlayer.create(this,R.raw.you);
if(v==play && !mp.isPlaying())
{
mp.start();
}
else if (v==stop) //this part of code executes but doesnot stop the
player
{
mp.stop();
mp.release();
}
}
No comments:
Post a Comment