0

I have created an array of sounds that is randomly accessed to play via MediaPlayer when a button is pressed - this works fine my only issue is that when testing it and pressing the button rapidly the sound would stop and not play anymore - is there some way I can implement a start stop thing? I tried beginning my onClick method with a butPress.stop() but my android emulator didn't like it. the code follows :

public void onClick(View arg0) {


try{
    display.setText(pp.getText());
    int x = r.nextInt(sfx.length);
    butPress = MediaPlayer.create(PitchMaker.this, sfx[x]);
    butPress.start();
}catch(Exception e){
    display.setText("Whoops we had a problem. Please try again");
}

}

4

1 回答 1

0

请在 catch 块中使用这行代码,以便我们可以得到准确的错误报告。

Toast.makeText(getApplicationContext(),e.toString(),Toast.LENGTH_SHORT).show();
于 2012-12-05T09:48:40.317 回答