私はアンドロイドのサウンドボードを作っています。いずれかのボタンをタッチすると音が鳴りますが、もう一度触れると音だけでなく他のボタンも動きません。一度に1つの音。私の主な活動は、ボタンの再生機能を呼び出すことです。ボタンをもう一度押すと音が止まる
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();
}
}