【发布时间】:2017-01-12 15:40:36
【问题描述】:
我正在尝试制作一个 android 音板。当我触摸任何按钮时它会发出声音,但是当我再次触摸它时,不仅声音停止,而且其他按钮都不起作用。我希望它一次播放一个声音。这里是我在按钮上调用播放功能的主要活动。
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();
}
}
【问题讨论】: