我的UI中有两个按钮。这两个按钮分别有两个音频,我已将其称为dk1
和dk2
。
我想要的是什么:
在按下dk1
时停止dk2
要一直重复此过程
我想创建另外6个音频,例如上面dk1
和dk2
问题:我不能不止这样做多次。这是我的代码:
public class MainActivity extends AppCompatActivity {
//Media Player Loops
//Loops
MediaPlayer dk1;
MediaPlayer dk2;
//Mediaplayer Location
dk1 = MediaPlayer.create(this, R.raw.dholak01);
dk2 = MediaPlayer.create(this, R.raw.dholak03);
}
//Looping and start Media Player
public void playdk1 (View view) {
if (dk1.isPlaying() == true) {
dk1.stop();
return;
}
if (dk2.isPlaying() == true) {
dk2.stop();
} else {
dk1.start();
dk1.setLooping(true);
}
}
public void playdk2 (View view) {
if (dk2.isPlaying() == true) {
dk2.stop();
return;
}
if (dk1.isPlaying() == true) {
dk1.stop();
} else {
dk2.start();
dk2.setLooping(true);
}
}
答案 0 :(得分:0)
public void playdk1 (View view)
if (dk1.isPlaying() == true) {
dk1.stop();
}
else{
dk2.start();
dk2.setLooping(true);}
if (dk2.isPlaying() == true) {
dk2.stop();
} else {
dk1.start();
dk1.setLooping(true);
}
}
public void playdk2 (View view) {
if (dk2.isPlaying() == true) {
dk2.stop();
}
else {
dk1.start();
dk1.setLooping(true);
}
if (dk1.isPlaying() == true) {
dk1.stop();
} else {
dk2.start();
dk2.setLooping(true);
}
}