我添加了" pause.Timer = true;"在媒体播放器代码和" pauseTimer = false之前;"在媒体播放器代码之后但应用显示当音频正在读取问题时计时器仍在播放。问题是简单的问题总结问题。我的代码错了吗?
这些是我的代码;
}开始();}
private int getScore(){
String scoreStr = scoreTxt.getText().toString();
return Integer.parseInt(scoreStr.substring(scoreStr.lastIndexOf(" ")+1));
}
private void chooseQuestion(){
answerTxt.setText("= ?");
QnNum = random.nextInt(QnsList.length);
final int DELAY_MS = 1000;
question.setText("Qn "+(questionNumber));
pauseTimer = true;
qn = MediaPlayer.create(this, QnsList[QnNum]);
qn.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer qn) {
qn.stop();
qn.reset();
qn.release();
qn = null;
}
});
if (leftTimeInMillisecondsGlobal == 0) {
if (countDownTimer != null) {
countDownTimer.cancel();
}
setTimer(originalTimerTimeInMilliSeconds);
} else {
if (countDownTimer != null) {
countDownTimer.cancel();
}
setTimer(leftTimeInMillisecondsGlobal);
}
pauseTimer = false;
startTimer();
qn.start();}
答案 0 :(得分:0)
虽然我不知道您的计时器是如何工作的,但建议解决方案。
移动pauseTimer = false;在MediaPlayer的onCompletionListener中。
例如:
private void chooseQuestion(){
answerTxt.setText("= ?");
QnNum = random.nextInt(QnsList.length);
final int DELAY_MS = 1000;
question.setText("Qn "+(questionNumber));
pauseTimer = true;
qn = MediaPlayer.create(this, QnsList[QnNum]);
qn.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer qn) {
qn.stop();
qn.reset();
qn.release();
qn = null;
pauseTimer = false;
}
});
if (leftTimeInMillisecondsGlobal == 0) {
if (countDownTimer != null) {
countDownTimer.cancel();
}
setTimer(originalTimerTimeInMilliSeconds);
} else {
if (countDownTimer != null) {
countDownTimer.cancel();
}
setTimer(leftTimeInMillisecondsGlobal);
}
startTimer();
qn.start();
}