我正在开发一个用于研究目的的应用程序。该应用程序需要两个500毫秒的声音一个接一个地播放,它们之间的间隔为500毫秒。问题是第一个声音没有完全播放完毕。它会在最后被削减。
public void playSounds(int num, int i) {
if (num == 1) {
try {
TimeUnit.MILLISECONDS.sleep(500);
mp.reset();
} catch (Exception ex) {
}
mp = MediaPlayer.create(getApplicationContext(), sounds[i]);
//i--;
mp.start();
//onPrepared(mp);
try {
TimeUnit.MILLISECONDS.sleep(500);
mp.reset();
} catch (Exception ex) {
}
mp = MediaPlayer.create(getApplicationContext(), sounds[0]);
mp.start();
//onPrepared(mp);
Log.d("Mytag", "RevCount is " + revCount);
} else if (num == 2) {
try {
TimeUnit.MILLISECONDS.sleep(500);
mp.reset();
} catch (Exception ex) {
}
mp = MediaPlayer.create(getApplicationContext(), sounds[0]);
mp.start();
//onPrepared(mp);
Log.d("Mytag", "RevCount is " + revCount);
try {
TimeUnit.MILLISECONDS.sleep(500);
mp.reset();
//Thread.sleep((long) 500.00);
} catch (Exception ex) {
}
mp = MediaPlayer.create(getApplicationContext(), sounds[i]);
//i--;
mp.start();
//onPrepared(mp);
}
}
我已经初始化了mediaPlayer对象。我似乎无法在这里找到错误。