I m trying to make a android soundboard.When i touch any button it produces sound but when i touch it again, not only sound stops but none of the other button works.I want it play one sound at a time.Here is my main activity i m calling the play functions on buttons.
public class MainActivity extends AppCompatActivity {
MediaPlayer whine, cry, weed, chup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
whine = MediaPlayer.create(this, R.raw.gone);
cry = MediaPlayer.create(this, R.raw.mock);
weed = MediaPlayer.create(this, R.raw.phen);
chup = MediaPlayer.create(this, R.raw.rg);
}
public void playwhine(View view) {
if (cry.isPlaying())
cry.stop();
if (weed.isPlaying())
weed.stop();
if (chup.isPlaying())
chup.stop();
whine.start();
}
public void playcry(View view) {
if (whine.isPlaying())
whine.stop();
if (weed.isPlaying())
weed.stop();
if (chup.isPlaying())
chup.stop();
cry.start();
}
public void playweed(View view) {
if (cry.isPlaying())
cry.stop();
if (whine.isPlaying())
whine.stop();
if (chup.isPlaying())
chup.stop();
weed.start();
}
public void playchup(View view) {
if (cry.isPlaying())
cry.stop();
if (whine.isPlaying())
whine.stop();
if (weed.isPlaying())
weed.stop();
chup.start();
}
}