所以我试图对所有按钮进行 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)