我试图在按回或按回家时停止我的声音放它不起作用请帮助我这是声音播放的代码,但我希望该方法在按回或按回家时停止。
public class Youcha3 extends Activity {
MediaPlayer mysound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_youcha3);
Button btsound=(Button)findViewById(R.id.dou3aa);
btsound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mysound=MediaPlayer.create(Youcha3.this, R.raw.dou3aa );
if (mysound.isPlaying()) {
mysound.pause();
mysound.release();
}
else{
mysound.start();
}
}
});
}