我有许多阵列声音的示例,我想在其他声音结束播放时播放下一个声音,并且声音阵列结束时没有重复,但是在阵列结束时会重复播放。如何使数组不重复?
我已经搜索了,但是我的问题没有解决
公共类balok扩展了AppCompatActivity {
int [] sound;
int soundke = 0;
MediaPlayer mediaPlayer;
int selesai = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_balok);
sound = new int[] {R.raw.swoosh1, R.raw.swoosh2, R.raw.decision};
mediaPlayer = MediaPlayer.create(balok.this, sound[0]);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
selesai++;
if (selesai == 2) {
mediaPlayer.release();
} else {
play();
}
}
});
}
private void play () {
soundke = (soundke+1) % 3;
AssetFileDescriptor afd = this.getResources().openRawResourceFd(sound[soundke]);
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
mediaPlayer.prepare();
mediaPlayer.start();
afd.close();
} catch (IOException e) {
}
}
我希望声音阵列完成后不会循环播放, 对不起,如果我的语言令人困惑,希望您能为我提供帮助