所以我试图为所有按钮做Onclick ...每当用户点击一些但是它去OnClickButton,然后播放一些声音..对于button1它将播放mp1为按钮2播放sound2 .... 所以一切正常,但是当我在一段时间后点击按钮上的很多东西时 声音刚刚停止播放.. 这是代码:
public void OnClick(View v) {
final MediaPlayer mp1 = MediaPlayer.create(this, R.raw.sound1);
final MediaPlayer mp2 = MediaPlayer.create(this, R.raw.sound2);
final MediaPlayer mp3 = MediaPlayer.create(this, R.raw.sound3);
final MediaPlayer mp4 = MediaPlayer.create(this, R.raw.sound4);
TextView mytv = (TextView) findViewById(R.id.tvMytimer);
int id = v.getId();
if (id == R.id.btComp1 || id==R.id.btUser1)
{
mytv.setText("Button 1");
mp1.start();
}
if (id == R.id.btComp2 || id==R.id.btUser2)
{
mytv.setText("Button 2");
mp2.start();
}
if (id == R.id.btComp3 || id==R.id.btUser3)
{
mytv.setText("Button 3");
mp3.start();
}
if (id == R.id.btComp4 || id==R.id.btUser4)
{
mytv.setText("Button 4");
mp4.start();
}
}
我还禁用所有随意按键音,因为我想要的只是声音是我的声音..
(disable with setSoundEffectsEnabled(false)