按下开始按钮时它开始播放 mp3 文件,但按下停止按钮时它不会停止,我已经通过几个例子但找不到确切的解决方案
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) </br>
{
mp = MediaPlayer.create(this,R.raw.you);
if(v==play && !mp.isPlaying()){
mp.start();
}
//below part of code executes but doesn't stop the player
else if (v==stop){
mp.stop();
mp.release();
}
}